News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Help needed with waveform audio stuff

Started by NoCforMe, February 15, 2015, 10:27:14 AM

Previous topic - Next topic

NoCforMe

I could use a little help with the Windoze waveform audio functions--specifically, the waveOutXXX() ones.

I'm working on a small app to test out these functions. I'm trying to generate WAV data programmatically, rather than reading a .wav file. Here's what I'm doing:

  • Seeing how many wave audio devices are installed on my computer with waveOutGetNumDevs(), which works fine: it tells me I have one device.

  • Getting the device's capabilities with waveOutGetDevCaps(), which tells me that it's a Realtek HD Audio output device which supports my requested format (WAVE_FORMAT_4M16, 44.1 kHz, mono, 16-bit).

  • Opening the device with waveOutOpen(), which works OK (I'm using no callbacks here, setting those parameters to NULL).

  • Allocating enough memory using HeapAlloc(), which works fine.

  • Generating my waveform into the memory thus allocated; I'm just creating a simple square wave of ~400 Hz for now.

  • Preparing my WAVEHDR header with waveOutPrepareHeader(), which works fine.

  • Writing the data to the wave device using waveOutWrite(), which fails. Ugh.

The error I get (translated using GetLastError() and FormatMessage()) is "Insufficient system resources exist to complete the requested service". That's not much help ...

So I'm thinking this might be a memory issue: do I need to lock the memory I get with HeapAlloc()? use a different allocation method? do something else to the memory before trying to write to the wave device? Or is it some other problem?

Oh, I should give you the contents of the structures I'm using:

$samplesPerSec EQU 44100
$toneDuration EQU 1 ;Duration in seconds.
$WaveBufferLen EQU $samplesPerSec * 2 * $toneDuration

WaveFmtStruct WAVEFORMATEX <WAVE_FORMAT_PCM, 1, $samplesPerSec, $samplesPerSec * 2, 2, 16, 0>
WaveHeaderStruct WAVEHDR <WaveBufferPtr, $WaveBufferLen, ?, ?, 0, 1>


(I'm setting the output device to 1 channel, 44.1 kHz sampling rate, 16-bit samples.) WaveBufferPtr is the pointer to the allocated memory.

I'm running XP (SP 3), have plenty o'memory (1 GB), not many apps running.

Any help would be appreciated. I can post the code later if needed.
Assembly language programming should be fun. That's why I do it.

adeyblue

Quote
The error I get (translated using GetLastError() and FormatMessage()) is "Insufficient system resources exist to complete the requested service". That's not much help ...
That's because these functions don't use GetLastError, they return any errors they generate. Don't use FormatMessage with it either, you'll have to lookup the value in the mmsystem include file to figure out which it is.

NoCforMe

Quote from: adeyblue on February 15, 2015, 11:14:30 AM
Quote
The error I get (translated using GetLastError() and FormatMessage()) is "Insufficient system resources exist to complete the requested service". That's not much help ...
That's because these functions don't use GetLastError, they return any errors they generate. Don't use FormatMessage with it either, you'll have to lookup the value in the mmsystem include file to figure out which it is.

Yes. (Ackshooly, it's in windows.inc.) I'm getting MMSYSERR_NOMEM, like I thought.
Assembly language programming should be fun. That's why I do it.

NoCforMe

Yarrrgh! I feel like such an idiot. Simple mistake; check out the values I put in my WAVEHDR structure. What was supposed to be the pointer to the wave buffer was actually a pointer to the variable that pointed to ... nevermind. Anyhow, it works fine now.

Now how many more times will I make this mistake before I learn?
Assembly language programming should be fun. That's why I do it.

anunitu

I remember a scene intro that was under 64k that as far as I understood produced a music output that was created from an assembler routine.

https://www.scene.org/file.php?file=/demos/groups/farb-rausch/fr08_final.zip&fileinfo

Known by the name "The Product" not sure if the source was available ever,but also a graphic from an asm routine

The link is for the exe I think.

https://www.scene.org/misc/best64kintros.php

Interesting is they made a youtube of this demo..at 64 k kinda interesting how they got the music and graphics in there.

https://www.youtube.com/watch?v=Y3n3c_8Nn2Y

Siekmanski

Some Demo Groups release there sources.
Here you can download some Farbrausch demo sources:

http://www.displayhack.org/2012/the-great-demoscene-sourcecode-giveaway/
Creative coders use backward thinking techniques as a strategy.

anunitu

The demo stuff always amazed me,what with the small size and the output..as an asm programmer I always wondered how they did this stuff.

Siekmanski

They use smart algorithms to generate textures, 3D objects, and soundwaves on the fly.
And executable and data crunchers to make it even smaller.
Creative coders use backward thinking techniques as a strategy.

GoneFishing

Thanks anunitu,
The Product demoscene is really impressive!
I found a site where the project is hosted:
http://www.theproduct.de

NoCforMe

Quote from: anunitu on February 16, 2015, 04:05:23 AM
The demo stuff always amazed me,what with the small size and the output..as an asm programmer I always wondered how they did this stuff.

Are you sure it's a waveform generator of some kind and not a MIDI app? MIDI can be pretty tiny.
Assembly language programming should be fun. That's why I do it.

dedndave

it's interesting that you are playing WAV from memory
if it's not too much trouble, a little example program would be really cool   :t

i have thought some of using that technique for morse code sounds
but - haven't found too much documentation on it
well, actually, too much documentation is the problem - lol
you have to read through miles of multi-media stuff to understand it

it can be done with MIDI pretty easily, but it's hard to make nice-sounding morse with MIDI

Siekmanski

Hi Dave,
Just curious, do you want to create a morse code receiver and transmitter ?
Creative coders use backward thinking techniques as a strategy.

dedndave

i didn't really have a specific app in mind
but sending and receiving would be 2 very different functions, as you probably know   :P

in the world of morse, it's one thing to have a logging program send code for you
it's considered a little bit lame to have a program receive for you - lol

the reason is - it's much easier to send code than copy it at speed
copy is the proof that you know code   :biggrin:
i've been doing it a long time, so it's easy for me

Siekmanski

Quote from: dedndave on February 17, 2015, 09:20:02 AM
in the world of morse, it's one thing to have a logging program send code for you
it's considered a little bit lame to have a program receive for you - lol

It could be handy for us lamers with a SDR stick to receive the "." and "-" codes in ascii.  :biggrin:
Creative coders use backward thinking techniques as a strategy.

dedndave

my opinion is ...
if you want to do that, we also have digital modes (packet, rtty, etc)
why not use one of those if you don't want to copy code

many countries have introduced "no-code licensing" over the past couple decades
a lot of old timers aren't too keen on that - they feel they had to learn it - why not the new guy

as for me, i don't care as much
if you want to be in a DX pile up or contest with morse, you have to know how to copy   :P