Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Why play it mono?

#pragma comment (lib, "winmm.lib")
#include <windows.h>
#include <mmsystem.h>
#include <stdlib.h> 

void CALLBACK waveInProc(HWAVEIN hwi,UINT uMsg,DWORD dwInstance,DWORD dwParam1,DWORD dwParam2);
bool addbuffer(WAVEHDR *pWaveHdr);

#define system_buf_len 4410
const int num_buff = 3;

HWAVEOUT hvo; 
HWAVEIN hvi; 

WAVEFORMATEX waveFormat;
WAVEHDR *whdrO; 
WAVEHDR buffer[num_buff];

int main()
{
	whdrO=(WAVEHDR*)malloc(sizeof(WAVEHDR));

	waveFormat.wFormatTag      = WAVE_FORMAT_PCM;
	waveFormat.wBitsPerSample  = 16;
	waveFormat.nChannels       = 2;
	waveFormat.nSamplesPerSec  = 44100;
	waveFormat.nBlockAlign     = (waveFormat.nChannels * waveFormat.wBitsPerSample) / 8;
	waveFormat.nAvgBytesPerSec = (waveFormat.nSamplesPerSec * waveFormat.nBlockAlign);
	waveFormat.cbSize          = 0;

	UINT uDevice = 0; 

	MMRESULT mmres;
	mmres = waveInOpen(&hvi,uDevice,&waveFormat,(DWORD)waveInProc,0,CALLBACK_FUNCTION);
	mmres = waveOutOpen(&hvo,WAVE_MAPPER,&waveFormat,0,0,CALLBACK_NULL);

	for (int i=0; i<num_buff; i++)
	{
		buffer[i].lpData          = (char*)malloc(system_buf_len);
		buffer[i].dwBufferLength  = system_buf_len;
		buffer[i].dwBytesRecorded = 0;
		buffer[i].dwUser          = 0;
		buffer[i].dwFlags         = 0;
		buffer[i].dwLoops         = 0;
		waveInPrepareHeader(hvi, &buffer[i], sizeof(WAVEHDR));
		waveInAddBuffer(hvi, &buffer[i], sizeof(WAVEHDR));
	}

	waveInStart(hvi);
	system("pause");
	waveInClose(hvi);
	waveOutClose(hvo);
	return 0;
}

void CALLBACK waveInProc(HWAVEIN hwi,UINT uMsg,DWORD dwInstance,DWORD dwParam1,DWORD dwParam2)
{
	WAVEHDR* pWaveHdr;
	switch(uMsg)
	{
		case MM_WIM_DATA:
			pWaveHdr = ((WAVEHDR*)dwParam1);
			if (pWaveHdr && hwi)
				if (pWaveHdr->dwFlags && WHDR_DONE == WHDR_DONE)
				{
					addbuffer(pWaveHdr); 
					waveInAddBuffer(hwi, pWaveHdr, sizeof(WAVEHDR)); 
				}
		break;
	}
}

bool addbuffer(WAVEHDR *waveHdr)
{	
	memcpy(whdrO,waveHdr,sizeof(WAVEHDR));
	waveInUnprepareHeader(hvi,waveHdr,sizeof(WAVEHDR));
	waveOutPrepareHeader(hvo,waveHdr,sizeof(WAVEHDR));
	waveOutWrite(hvo,whdrO, sizeof(WAVEHDR)); 

	return true;
}
Posted
Comments
Richard MacCutchan 2-Sep-10 14:36pm    
Why indeed!
Aescleal 2-Sep-10 19:40pm    
Because stereo isn't retro enough?
LittleYellowBird 3-Sep-10 3:19am    
Hi, you need to provide more information about what your problem is, no one can answer at the moment because we don't know what is wrong. OK? :)
E.F. Nijboer 14-Sep-10 10:09am    
Did you check the file you're playing? Maybe it's mono?
Did you play with the "balance" and change it so only one speaker gets the signal?

1 solution

I had a problem where the 16-bit stereo audio was only playing from one speaker. This sounds like what you are describing here. If that is the problem try this "what seems' obvious solution. It fixed my problem:

waveOutSetVolume( hwo, 0xFFFFFFFF );

Even though the volume mixer was fine and I could check the mixer application and play sound with winamp in stereo, my program was playing in mono from one speaker.
 
Share this answer
 
Comments
Dalek Dave 19-Oct-10 3:23am    
Good Call.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900