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.
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.
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.
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?
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
Some Demo Groups release there sources.
Here you can download some Farbrausch demo sources:
http://www.displayhack.org/2012/the-great-demoscene-sourcecode-giveaway/
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.
They use smart algorithms to generate textures, 3D objects, and soundwaves on the fly.
And executable and data crunchers to make it even smaller.
Thanks anunitu,
The Product demoscene is really impressive!
I found a site where the project is hosted:
http://www.theproduct.de
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.
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
Hi Dave,
Just curious, do you want to create a morse code receiver and transmitter ?
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
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:
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
: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.
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)
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....
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)
I made a small test.
Removed attachment, see Reply #21.
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 ?
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
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
Especially when you want to have a nice and clean sinus without spurs. :t