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

adeyblue

QuoteSomething to read
http://www.techmind.org/wave/
Quoteto be continued...

Last modified: 7 September 2006
Ah, a blogger after my own heart.

There's an MSDN example for doing what this does (recording from the default input) with WASAPI (search IAudioClient Capturing a Stream).
It's about the same amount of code once you modify this example to support arbitrary length recording with multiple WAVE buffers.

NoCforMe

Yeah, pretty good blog post, nice and clear.
So basically what I imagined doing, opening an input device and setting up sufficient buffers. I think I can handle that.

I'm going to go the waveXXXX() route rather than opening a new can o'worms (WASAPI). Should do everything I need it to do.
32-bit code and Windows 7 foreva!

NoCforMe

#17
So, some progress:
I've built my metronome circuit and connected it to my computah's line-in input (via a potentiometer to adjust the level), and I was able to do a recording with Sound Forge (an ancient copy from Windoze 2000 that still works):

You cannot view this attachment.

(Just to give you an idea, each of those pulses--the vertical things sticking up--is about 900 samples wide at a sampling frequency of 44.1kHz.)

And I've pretty much figured out how to get a look at that sound data with Win32 Waveform Audio functions. Not easy but doable: I'll have to do buffer management, but I think I have a handle on how the whole scheme will work.

Will report back when more progress has been made.
32-bit code and Windows 7 foreva!

sinsi

How are you using the menetrome's output? Such an output would be easy to generate for any BPM value, and be exact.

stoo23

I must admit, I have NOT been seriously following this thread but Audacity has an In-Built Metronome function and is both Free and a great program !!

NoCforMe

Quote from: sinsi on June 05, 2025, 05:27:15 PMHow are you using the menetrome's output? Such an output would be easy to generate for any BPM value, and be exact.

I'm building a physical stand-alone metronome and I want to calibrate its BPM values, hence the connection to the sound card.

Formula is BPM = sampling frequency / # of samples * 60.

I've got it pretty much figured out except for some tricky buffer-management cases:
  • What if I'm at the end of a buffer and the driver is still working on filling the other buffer (I'm hoping to use just two)? In that case I just have to twiddle my thumbs until the other buffer is "done".
  • What if I'm processing a buffer, am in the middle of it but then the other buffer is done by the driver? Now we have the classic buffer overrun condition which I'd have to handle (just dump the data on the floor). But hopefully my code will be fast enough to avoid this situation. Speed really does matter here.
32-bit code and Windows 7 foreva!

NoCforMe

Quote from: stoo23 on June 05, 2025, 06:21:36 PMI must admit, I have NOT been seriously following this thread but Audacity has an In-Built Metronome function and is both Free and a great program !!

Well, for that matter it would be super easy to write a metronome program.
But I don't want to have to use a desktop computer for that simple function. My metronome fits in a small tin and runs on a 9-volt battery.
32-bit code and Windows 7 foreva!

sinsi


NoCforMe

Quote from: sinsi on June 06, 2025, 10:00:15 AM
Quote from: NoCforMe on June 06, 2025, 02:56:43 AMSpeed really does matter here.
Multithreading should speed things up.

Yes, the buffer-reading code will go into a separate thread, so the UI remains responsive.
32-bit code and Windows 7 foreva!

stoo23

So do you not have access to an Oscilloscope ??

NoCforMe

Quote from: stoo23 on June 06, 2025, 01:51:47 PMSo do you not have access to an Oscilloscope ??

Yes, I do; I have an older Tektronix 475.  But that wouldn't be at all accurate; I might be able to get within 20% of the pulse spacing for BPM. Not good enough.

Might be able to get pretty close with a modren DSO, but I don't have one of those.

The sound card method lets me get super close to exact, as I can actually count samples (1/44,100 sec.).
32-bit code and Windows 7 foreva!

stoo23

Hmmm OK, well, you've effectively Lost me, I would have thought even the 475 @ 200mHz would have been adequate.  :dazzled:

NoCforMe

Quote from: stoo23 on June 06, 2025, 02:22:19 PMHmmm OK, well, you've effectively Lost me, I would have thought even the 475 @ 200mHz would have been adequate.  :dazzled:

Yes, it has that bandwidth, but what it doesn't have is enough resolution to calibrate BPM from a (verrrry slow) signal.

Keep in mind how far apart metronome clicks are spaced, which is what I need to measure. 200MHz ain't gonna help there.
32-bit code and Windows 7 foreva!

TimoVJL

A long time ago tested a two microphones for testing, how window might dampens noices.
With two similar microphones it might be possible, as switching those, an average value might be quite close.
That project was never accepted, as don't offer any easy solution for persons, who want use their relations for labs.
May the source be with you

NoCforMe

Quote from: TimoVJL on June 06, 2025, 10:22:06 PMA long time ago tested a two microphones for testing, how window might dampens noices.
With two similar microphones it might be possible, as switching those, an average value might be quite close.
That project was never accepted, as don't offer any easy solution for persons, who want use their relations for labs.

Sounds like you were attempting noise cancellation, right?

That's tricky, because you really need an accurate inverse phase signal for that to work. Lotsa signal processing, probably better done in hardware.
32-bit code and Windows 7 foreva!