|
/*--------------------------------------------------------------------------------
'Nom du projet : Oscilloscope
'Outil : Visual C++ 6
'Nom du fichier: WavePlay.cpp : implementation file
'Realisation:Mathieu Texier et Emmanuel Traineau
'Date: Juin 2003
'Responsable: Eric Meleiro
'--------------------------------------------------------------------------------
Explications : Ouverture et enregistrement des fichiers sons
*/
#include "stdafx.h"
#include "WavePlay.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CWavePlay::CWavePlay()
{
m_hwo = NULL;
}
CWavePlay::~CWavePlay()
{
Stop();
}
// test le WavePlayer
BOOL CWavePlay::IsActive (void)
{ if (m_hwo)
return TRUE;
else
return FALSE;
}
// Arret de la lecture du fichier WAV
void CWavePlay::Stop (void)
{
m_hwo = 0;
}
// Enregistrement d'un fichier WAV
void CWavePlay::MakeWaveFile (WORD channels, DWORD frequency, WORD bps,
void* data, DWORD length, LPSTR fname)
{
BYTE wavehead[] = {'R','I','F','F',
0, 0, 0, 0, // DWORD: Filelaenge - 8
'W','A','V','E',
'f','m','t',' ',
16, 0, 0, 0, // Konstant
1, 0, // Konstant
0, 0, // WORD: Kanaele
0, 0, 0, 0, // DWORD: Sample Freqenz
0, 0, 0, 0, // DWORD: Average
0, 0, // WORD: Bytes pro Sample
0, 0, // WORD: format-specific
'd','a','t','a',
0, 0, 0, 0}; // DWORD: Laenge Samplingdaten
// Entête du fichier
*(DWORD *)(&wavehead[4]) = length + sizeof(wavehead) - 8;
*(WORD *)(&wavehead[22]) = channels;
*(DWORD *)(&wavehead[24]) = frequency;
*(DWORD *)(&wavehead[28]) = channels * bps/8 * frequency;
*(WORD *)(&wavehead[32]) = bps/8;
*(WORD *)(&wavehead[34]) = bps;
*(DWORD *)(&wavehead[40]) = length;
// File anlegen und Header schreiben
CFile cf (fname, CFile::modeCreate | CFile::modeReadWrite);
cf.Write (wavehead, sizeof (wavehead));
// ... und Daten hinterher
cf.Write (data, length);
}
|
|
|