Solved

Low level MM in win32

Posted on 1999-01-28
7
251 Views
Last Modified: 2010-04-15
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
Comment
Question by:abmo
7 Comments
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1258492
Yes, there is something similar.

You should use mixerSetControlDetails() and mixerGetControlDetails(). Also look into mixerGetLineControls().
0
 

Author Comment

by:abmo
ID: 1258493
Sorry for rejecting, but can you insert some working example which can play (or record) something?  
0
 
LVL 1

Expert Comment

by:The_Raven
ID: 1258494
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:abmo
ID: 1258495
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
 

Expert Comment

by:core123
ID: 1258496
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
 
LVL 1

Accepted Solution

by:
The_Raven earned 100 total points
ID: 1258497
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
 

Author Comment

by:abmo
ID: 1258498
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now