• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

Low level MM in win32

In linux you can play or record sound (from sound card) just with opening file "dev/dsp" and change settings with ioctl. Are there similar functions in win32 API? Please any short working example.
0
abmo
Asked:
abmo
1 Solution
 
Tommy HuiCommented:
Yes, there is something similar.

You should use mixerSetControlDetails() and mixerGetControlDetails(). Also look into mixerGetLineControls().
0
 
abmoAuthor Commented:
Sorry for rejecting, but can you insert some working example which can play (or record) something?  
0
 
The_RavenCommented:
Play Sound...

#define MSG_SIZE 1024
char Msg[MSG_SIZE+1];

mciSendString("open test.wav type waveaudio alias mywave",Msg, MSG_SIZE, (HANDLE)hWnd);
mciSendString("set mywave time format samples",Msg, MSG_SIZE, (HANDLE)hWnd);
mciSendString("play mywave from 1 waid",Msg, MSG_SIZE, (HANDLE)hWnd);
mciSendString("close mywave",Msg, MSG_SIZE, (HANDLE)hWnd);

------------------------------------------------------------
Record Sound...

mciSendString("open new type waveaudio alias mywave",Msg, MSG_SIZE, (HANDLE)hWnd);
mciSendString("record mywave",Msg, MSG_SIZE, (HANDLE)hWnd);

// Do something here until record is terminated

mciSendString("stop mywave",Msg, MSG_SIZE, (HANDLE)hWnd);
mciSendString("save mywave tst.wav",Msg, MSG_SIZE, (HANDLE)hWnd);
mciSendString("close mywave",Msg, MSG_SIZE, (HANDLE)hWnd);

That is the easyest way to do it.

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
abmoAuthor Commented:
Ehm, sorry, that is for MCI and wave file. But isn´t there any possibility to read and write sound as a file (or something similar)?
Exactly I need to display "volume" in peaks of dB of incoming sound (so I need to "read" samples to memory), analyze it (at a sampling rate of 32000Hz) in real time, and then record (only good :-) samples) or do something. And I think there should be some low level MM functions to do that, but I didn´t found it yet...
Can you help me?
0
 
core123Commented:
Look for some documentation on the waveIn* functions such as waveInOpen(), they'll enable you to record sound on the windows system.  Hope you can find some :)
0
 
The_RavenCommented:
Are you looking for a double buffering system, something like this ? (This is something I wrote using Imprise C++ Builder)

VOID StartRecord(void)
{
   MMRESULT rc;
   int      i;
   MMTIME   mmtime;

// prepare buffer blocks and add to input queue
//.............................................

for (i = 0; i < MAX_BUFFERS; i++)      {                                                              
  rc = waveInPrepareHeader(hwi, wh[i], sizeof(WAVEHDR));    
  // add buffers to the input queue                            
  if (rc == MMSYSERR_NOERROR)
    rc = waveInAddBuffer(hwi, wh[i], sizeof(WAVEHDR));
   if (rc != MMSYSERR_NOERROR
   {waveInGetErrorText(rc, msg, MSG_LEN),                        
    MessageBox(Application->Handle, msg, NULL, MB_OK);
    StopRecord();  // free allocated memory
    return; }
                                    }
// start recording                                              
//................                                              
                                                                   rc = waveInStart(hwi);
    mmtime.wType = TIME_SAMPLES;
    rc = waveInGetPosition(hwi, &mmtime, sizeof(MMTIME));
    if (rc != MMSYSERR_NOERROR)
    {
      waveInGetErrorText(rc, msg, MSG_LEN),
      MessageBox(Application->Handle, msg, NULL, MB_OK);
    }                                          
}
0
 
abmoAuthor Commented:
YES YES YES, that it is, thank you all. It is a bit more complicated, than I thinked about. The_Raven just can you add some note (example) on how to get "hwi" handler?
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now