Solved

Low level MM in win32

Posted on 1999-01-28
7
253 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

920 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

15 Experts available now in Live!

Get 1:1 Help Now