Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Low level MM in win32

Posted on 1999-01-28
7
257 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 

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

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delete-remove 14 97
outlook office 365 8 144
Constant string is of type char *   ? 7 42
Test the speeds on my PC Drives 12 62
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

829 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