News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

How do I get access to my soundcard's output?

Started by NoCforMe, June 03, 2025, 11:13:30 AM

Previous topic - Next topic

NoCforMe

I'm confused and need a bit o'help here.

I want be able to tap into my soundcard's output, meaning the sound that's currently playing through it (using the card's line input).

There are two Wave functions: waveInOpen() and waveOutOpen().

In reading their descriptions I'm not sure either one is what I want:
  • For waveInOpen():
    QuoteThe function selects a waveform-audio input device capable of recording in the specified format.
  • For waveOutOpen():
    QuoteThe function selects a waveform-audio output device capable of playing the specified format.
But I don't want either to record or to play back: I guess what I want is to intercept the playback stream. Is that an input device or an output device?

I guess I just need to be set straight on the proper point of view here.
32-bit code and Windows 7 foreva!

zedd

Some hints that might be useful here...
QuoteWindows (WASAPI/DirectSound):
WASAPI (Windows Audio Session API): The modern API for audio in Windows. It offers low-latency and high-fidelity audio capabilities.
DirectSound: An older API, still available but generally superseded by WASAPI.
:biggrin:

NoCforMe

So Zedd, have you actually used this interface? or are you just suggesting something you found after an online search?

Looks a bit too abstract (C++-ish) for my taste.
32-bit code and Windows 7 foreva!

zedd

Quote from: NoCforMe on June 03, 2025, 12:29:10 PMSo Zedd, have you actually used this interface? or are you just suggesting something you found after an online search?
No, and from a brief online search.

Siekmanski is probably the best source here for how to proceed with what you are after. He has done extensive work with DirectSound iirc.

The only audio work I (and probably most here) have done is to play an MP3 file. That was pretty simple. What you are after sounds like it will be very complicated, and probably involve COM interfaces, etc.
:biggrin:

NoCforMe

Quote from: zedd on June 03, 2025, 12:34:35 PM
Quote from: NoCforMe on June 03, 2025, 12:29:10 PMSo Zedd, have you actually used this interface? or are you just suggesting something you found after an online search?
No, and from a brief online search.

Siekmanski is probably the best source here for how to proceed with what you are after. He has done extensive work with DirectSound iirc.

The only audio work I (and probably most here) have done is to play an MP3 file. That was pretty simple. What you are after sounds like it will be very complicated, and probably involve COM interfaces, etc.

OK. Sorry to ding you here, but in the future, would you please kindly not post any suggestions like that unless you actually know what the fuck they do and how to use them?

Not helpful at all. And yes, I also know how to do online searches, believe it or not.
32-bit code and Windows 7 foreva!

sinsi

DirectSound used to let you access the primary output buffer, not sure about the new audio interface (xaudio2).
It can be hard to get access to what's playing because the content creators don't want you to have an easy way to, for example, rip an encoded dvd.

Either way I think you're stuck with an interface or three.

NoCforMe

Quote from: zedd on June 03, 2025, 12:34:35 PMWhat you are after sounds like it will be very complicated, and probably involve COM interfaces, etc.

I sincerely hope not.
I'm merely trying to intercept an audio stream originating from my line-in input to analyze it (actually the output of an electronic device). I don't see why I'd have to use COM here for such a simple thing.
32-bit code and Windows 7 foreva!

NoCforMe

Quote from: sinsi on June 03, 2025, 12:54:16 PMDirectSound used to let you access the primary output buffer, not sure about the new audio interface (xaudio2).
It can be hard to get access to what's playing because the content creators don't want you to have an easy way to, for example, rip an encoded dvd.

Either way I think you're stuck with an interface or three.

Well, people actually implement things like digital oscilloscopes using the sound card, so they must have some way of accessing the card's stream, right?

(Not what I'm doing, but somewhat similar.)
32-bit code and Windows 7 foreva!

sinsi

If we knew the data you're trying to input it might magk it easier.
For true digital data an analogue line-in probably won't work whereas a USB connection might.

NoCforMe

Quote from: sinsi on June 03, 2025, 01:20:19 PMIf we knew the data you're trying to input it might magk it easier.
For true digital data an analogue line-in probably won't work whereas a USB connection might.

The data would be a series of clicks. Basically just short pulses (square wave-ish) generated by a metronome circuit which I want to calibrate.

Why wouldn't line in work where USB would? Line in gets digitized through the sound card.
What's the connection between USB and the sound card?
I guess you can plug in an iPod and have it play through the PC, yes? But I have no experience with that and no knowledge of how it works.
32-bit code and Windows 7 foreva!

sinsi

Quote from: NoCforMe on June 03, 2025, 01:37:59 PMLine in gets digitized through the sound card.
The problem is that it takes a variable input (analogue) and converts it to digital.
The signal is sampled e.g. 44100 times a second and the value is somehow converted to a level (electrical?).
Now we have a digital number we need a bitrate, usually 8 or 16, but we also need to work out which level is noise or silence. With digital, 0 is silence and 1 is noise. With analog, the ADC might treat anything below an arbitrary number as silence.

If you are using some type of pulse or square wave it may be easier.
If you know your output you have a better idea of levels and limits, they should be in the specs.


Think of how a serial port works, baud versus samples/sec.

daydreamer

Instead of sending to USB,sending to external monitor You can get sound, despite sound card speaker is wrecked, or thru Bluetooth headset on newer pc
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

NoCforMe

Quote from: sinsi on June 03, 2025, 02:43:13 PM
Quote from: NoCforMe on June 03, 2025, 01:37:59 PMLine in gets digitized through the sound card.
The problem is that it takes a variable input (analogue) and converts it to digital.
The signal is sampled e.g. 44100 times a second and the value is somehow converted to a level (electrical?).
Now we have a digital number we need a bitrate, usually 8 or 16, but we also need to work out which level is noise or silence. With digital, 0 is silence and 1 is noise. With analog, the ADC might treat anything below an arbitrary number as silence.

Well, it's a little less mysterious than that:
The ADC (analog to digital converter) outputs a number corresponding to the level of the input, where the input is scaled to some value; let's say for example the input ranges between -1 volt and 1 volt, representing the minimum and maximum values. (The level needs to be adjusted electrically on the input to the sound card.) 0 volts input always gives an output of 0; 1 volt would be 32,767 (assuming 16-bit data) and -1 volt would be -32,768, and anything in between is, well, in between.

The other settings--bitrate, # of channels and # of bits--are set through the driver (for a typical .WAV file these would be 44.1KHz, 2 channels and 16 bits). So that's not a problem.

The problem is just how do I get access to this data? I know it's possible, I just don't know how.
32-bit code and Windows 7 foreva!

sinsi

Well waveInOpen is your only choice, but Windows needs to know which device it is.

TimoVJL

May the source be with you