The MASM Forum

General => The Workshop => Topic started by: NoCforMe on February 15, 2015, 10:27:14 AM

Title: Help needed with waveform audio stuff
Post by: NoCforMe on February 15, 2015, 10:27:14 AM
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:

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.
Title: Re: Help needed with waveform audio stuff
Post by: 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.
Title: Re: Help needed with waveform audio stuff
Post by: NoCforMe on February 15, 2015, 11:32:04 AM
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.
Title: Re: Help needed with waveform audio stuff
Post by: NoCforMe on February 15, 2015, 04:51:29 PM
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?
Title: Re: Help needed with waveform audio stuff
Post by: anunitu on February 16, 2015, 12:43:55 AM
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
Title: Re: Help needed with waveform audio stuff
Post by: Siekmanski on February 16, 2015, 03:50:44 AM
Some Demo Groups release there sources.
Here you can download some Farbrausch demo sources:

http://www.displayhack.org/2012/the-great-demoscene-sourcecode-giveaway/
Title: Re: Help needed with waveform audio stuff
Post by: 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.
Title: Re: Help needed with waveform audio stuff
Post by: Siekmanski on February 16, 2015, 07:21:44 AM
They use smart algorithms to generate textures, 3D objects, and soundwaves on the fly.
And executable and data crunchers to make it even smaller.
Title: Re: Help needed with waveform audio stuff
Post by: GoneFishing on February 16, 2015, 09:01:53 AM
Thanks anunitu,
The Product demoscene is really impressive!
I found a site where the project is hosted:
http://www.theproduct.de
Title: Re: Help needed with waveform audio stuff
Post by: NoCforMe on February 16, 2015, 12:31:08 PM
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.
Title: Re: Help needed with waveform audio stuff
Post by: dedndave on February 17, 2015, 03:58:35 AM
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
Title: Re: Help needed with waveform audio stuff
Post by: Siekmanski on February 17, 2015, 09:03:38 AM
Hi Dave,
Just curious, do you want to create a morse code receiver and transmitter ?
Title: Re: Help needed with waveform audio stuff
Post by: dedndave on February 17, 2015, 09:20:02 AM
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
Title: Re: Help needed with waveform audio stuff
Post by: Siekmanski on February 17, 2015, 09:30:21 AM
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:
Title: Re: Help needed with waveform audio stuff
Post by: dedndave on February 17, 2015, 09:35:02 AM
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
Title: Re: Help needed with waveform audio stuff
Post by: Siekmanski on February 17, 2015, 09:49:30 AM
 :biggrin: :biggrin: :biggrin:

You want to play a sine wave by hitting a key right ?
You could also do that using DirectSound filling a sound buffer with a sine wave and play that buffer with the frequency you need and as long as you want just like a morse key.
Title: Re: Help needed with waveform audio stuff
Post by: dedndave on February 17, 2015, 10:29:49 AM
i get that
and i can do it with MIDI, too
but a solid beep turning off and on is very brash - a clickish sound to it
for nice morse, the wave shape attack and decay need to be shaped a little bit
something i can do easier with WAV

this one is probably a little too soft on attack and a little too stiff on decay, but you get the idea...

(http://www.solorb.com/elect/hamcirc/sidetone/cwwave.jpg)
Title: Re: Help needed with waveform audio stuff
Post by: Siekmanski on February 17, 2015, 10:53:59 AM
If you create a sine wave starting and ending at zero there's no click.
There are 2 ways to play a sample, looping and one shot.
With one shot you can shape the sample the way you want without a clicking sound.
I'm now curious if you stop a perfect sine wave at once you will hear a click.
I'll test this....
Title: Re: Help needed with waveform audio stuff
Post by: dedndave on February 17, 2015, 11:26:22 AM
another image
again, a little too soft on attack, but the decay looks better than the other one

(http://www.sm5bsz.com/dynrange/dubus204/rc_ideal_time.gif)
Title: Re: Help needed with waveform audio stuff
Post by: Siekmanski on February 17, 2015, 01:13:22 PM
I made a small test.

Removed attachment, see Reply #21.
Title: Re: Help needed with waveform audio stuff
Post by: dedndave on February 17, 2015, 03:52:59 PM
nice - but seems a bit harsh
i don't understand the code - lol
i generally use a sidetone of about 750 Hz, though

need a storage scope to examine the modulation envelope   :(
is it just me, or is the envelope different on different keypresses ?
Title: Re: Help needed with waveform audio stuff
Post by: Siekmanski on February 18, 2015, 01:15:29 AM
Yes Dave, you were right it was a bad example.  :redface:
I shouldn't code anymore late at night.  :biggrin:

Now with a correct 750 Hz sine wave with adjustable attack and decay.

edit: minor correction
Title: Re: Help needed with waveform audio stuff
Post by: dedndave on February 18, 2015, 05:28:08 AM
very cool - give me some time to play...

thanks, Marinus   :t

not as easy as it sounds - lol
the same is true if you are trying to make a nice code practice oscillator   :biggrin:
takes a lot of circuitry to make it sound right
Title: Re: Help needed with waveform audio stuff
Post by: Siekmanski on February 18, 2015, 07:23:44 AM
Especially when you want to have a nice and clean sinus without spurs.  :t