USB audio-streaming

R

r2d2droids

Guest
Hej alle,
Jeg sender analog audio signaler ved hjælp pic (A / D-modul) via sci til FT232 chip.efter at jeg ønsker at skrive disse digitale signaler til et bestemt buffer, og efter buffer fylder, sender de signaler til lydenhed til afspilning.
Jeg har fundet en kilde kode, der kan optage og afspille den bølge ved hjælp af mikrofon.men JEG kunne tilpasse denne kode til mit projekt.
koden er vist nedenfor:

//------------------------------------------------ ---------------------------
# include <vcl\vcl.h>
# pragma hdrstop

# include "WaveformAPI.h"
//------------------------------------------------ ---------------------------
# pragma resource "*. dfm"
TForm1 * Form1;
//------------------------------------------------ ---------------------------

/************************************************* ******************** \
* WaveHeader (WAVEHDR) wrapper funktioner
\ ************************************************* ********************/

bool WaveMakeHeader (unsigned long ulSize, hGlobal & HData, hGlobal & HWaveHdr,
LPSTR & lpData, LPWAVEHDR & lpWaveHdr)
(
HData = GlobalAlloc (GMEM_MOVEABLE | GMEM_SHARE, ulSize);
if (! HData) return false;

lpData = (LPSTR) GlobalLock (HData);
if (! lpData)
(
GlobalFree (HData);
return false;
)

HWaveHdr = GlobalAlloc (GMEM_MOVEABLE | GMEM_SHARE, sizeof (WAVEHDR));
if (! HWaveHdr)
(
GlobalUnlock (HData);
GlobalFree (HData);
return false;
)

lpWaveHdr = (LPWAVEHDR) GlobalLock (HWaveHdr);
if (! lpWaveHdr)
(
GlobalUnlock (HWaveHdr);
GlobalFree (HWaveHdr);
GlobalUnlock (HData);
GlobalFree (HData);
return false;
)

ZeroMemory (lpWaveHdr, sizeof (WAVEHDR));
lpWaveHdr-> lpData = lpData;
lpWaveHdr-> dwBufferLength = ulSize;

return true;
)
//------------------------------------------------ ---------------------------

void WaveFreeHeader (hGlobal & HData, hGlobal & HWaveHdr)
(
GlobalUnlock (HWaveHdr);
GlobalFree (HWaveHdr);
GlobalUnlock (HData);
GlobalFree (HData);
)
//------------------------------------------------ ---------------------------

/************************************************* ******************** \
* WaveIn (optagelse) wrapper funktioner
\ ************************************************* ********************/

bool WaveRecordOpen (LPHWAVEIN lphwi, HWND hwnd, int nChannels,
lang lFrequency, int nBits)
(
WAVEFORMATEX wfx;
wfx.wFormatTag = WAVE_FORMAT_PCM;
wfx.nChannels = (Word) nChannels;
wfx.nSamplesPerSec = (DWORD) lFrequency;
wfx.wBitsPerSample = (Word) nBits;
wfx.nBlockAlign = (Word) ((wfx.nChannels * wfx.wBitsPerSample) /

<img src="http://www.edaboard.com/images/smiles/icon_cool.gif" alt="Kølig" border="0" />

;
wfx.nAvgBytesPerSec = (wfx.nSamplesPerSec * wfx.nBlockAlign);
wfx.cbSize = 0;

MMRESULT resultat = waveInOpen (lphwi, WAVE_MAPPER, & wfx, (lang) hwnd, NULL,
CALLBACK_WINDOW);

if (result == MMSYSERR_NOERROR) return true;
return false;
)
//------------------------------------------------ ---------------------------

bool WaveRecordBegin (HWAVEIN HWI, LPWAVEHDR & lpWaveHdr)
(
MMRESULT resultat = waveInPrepareHeader (HWI, lpWaveHdr, sizeof (WAVEHDR));
if (result == MMSYSERR_NOERROR)
(
MMRESULT resultat = waveInAddBuffer (HWI, lpWaveHdr, sizeof (WAVEHDR));
if (result == MMSYSERR_NOERROR)
(
MMRESULT resultat = waveInStart (HWI);
if (result == MMSYSERR_NOERROR) return true;
)
)
return false;
)
//------------------------------------------------ ---------------------------

void WaveRecordEnd (HWAVEIN HWI, LPWAVEHDR & lpWaveHdr)
(
waveInStop (HWI);
waveInReset (HWI);
waveInUnprepareHeader (HWI, lpWaveHdr, sizeof (WAVEHDR));
)
//------------------------------------------------ ---------------------------

void WaveRecordClose (HWAVEIN HWI)
(
waveInReset (HWI);
waveInClose (HWI);
)
//------------------------------------------------ ---------------------------

/************************************************* ******************** \
* WaveOut (afspilning) wrapper funktioner
\ ************************************************* ********************/

bool WavePlayOpen (LPHWAVEOUT lphwo, HWND hwnd, int nChannels,
lang lFrequency, int nBits)
(
WAVEFORMATEX wfx;
wfx.wFormatTag = WAVE_FORMAT_PCM;
wfx.nChannels = (Word) nChannels;
wfx.nSamplesPerSec = (DWORD) lFrequency;
wfx.wBitsPerSample = (Word) nBits;
wfx.nBlockAlign = (Word) ((wfx.nChannels * wfx.wBitsPerSample) /

<img src="http://www.edaboard.com/images/smiles/icon_cool.gif" alt="Kølig" border="0" />

;
wfx.nAvgBytesPerSec = (wfx.nSamplesPerSec * wfx.nBlockAlign);
wfx.cbSize = 0;

MMRESULT resultat = waveOutOpen (lphwo, WAVE_MAPPER, & wfx, (lang) hwnd, NULL,
CALLBACK_WINDOW);

if (result == MMSYSERR_NOERROR) return true;
return false;
)
//------------------------------------------------ ---------------------------

bool WavePlayBegin (HWAVEOUT hwo, LPWAVEHDR & lpWaveHdr)
(
MMRESULT resultat = waveOutPrepareHeader (hwo, lpWaveHdr, sizeof (WAVEHDR));
if (result == MMSYSERR_NOERROR)
(
MMRESULT resultat = waveOutWrite (hwo, lpWaveHdr, sizeof (WAVEHDR));
if (result == MMSYSERR_NOERROR) return true;
)
return false;
)
//------------------------------------------------ ---------------------------

void WavePlayEnd (HWAVEOUT hwo, LPWAVEHDR & lpWaveHdr)
(
waveOutReset (hwo);
waveOutUnprepareHeader (hwo, lpWaveHdr, sizeof (WAVEHDR));
)
//------------------------------------------------ ---------------------------

void WavePlayClose (HWAVEOUT hwo)
(
waveOutReset (hwo);
waveOutClose (hwo);
)
//------------------------------------------------ ---------------------------/************************************************* ******************** \
* Eksempel brug ...
\ ************************************************* ********************/

__fastcall TForm1:: TForm1 (TComponent * Ejeren)
: TForm (Ejer)
(
ulSize = 1000000;
FAllocated = false;
FRecording = false;
FPlaying = false;

TrackBar1-> Max = 0xFFFF;
TrackBar1-> Frequency = 1000;

DWORD current_volume;
waveOutGetVolume (0, & current_volume);
TrackBar1-> Position = TrackBar1-> Max - LOWORD (current_volume);
)
//------------------------------------------------ ---------------------------

__fastcall TForm1:: ~ TForm1 ()
(
if (FAllocated) WaveFreeHeader (HData, HWaveHdr);
if (FRecording) WaveRecordClose (HWI);
if (FPlaying) WavePlayClose (hwo);

)
//------------------------------------------------ ---------------------------

void __fastcall TForm1:: RecordButtonClick (TObject * Sender)
(
if (WaveRecordOpen (& HWI, Handle, 2, 44100, 16))
(
if (WaveMakeHeader (ulSize, HData, HWaveHdr, lpData, lpWaveHdr))
(
FAllocated = true;
if (WaveRecordBegin (HWI, lpWaveHdr))
(
FRecording = true;
Caption = "Optagelse ...";
Shape1-> Brush-> Color = clRed;
StopButton-> Enabled = true;
RecordButton-> Enabled = false;
)
)
)
)
//------------------------------------------------ ---------------------------

void __fastcall TForm1:: StopButtonClick (TObject * Sender)
(
if (FRecording)
(
WaveRecordEnd (HWI, lpWaveHdr);
FRecording = false;
)
if (FPlaying)
(
WavePlayEnd (hwo, lpWaveHdr);
FPlaying = false;
Shape2-> Brush-> Color = clBlack;
StopButton-> Enabled = false;
)
)
//------------------------------------------------ ---------------------------

void __fastcall TForm1:: MMWimData (TMessage & Msg)
(
Caption = "Done RECORDING";
if (FRecording) WaveRecordEnd (HWI, lpWaveHdr);
WaveRecordClose (HWI);

if (WavePlayOpen (& hwo, Handle, 2, 44100, 16))
(
ShowMessage ( "Klik OK for at begynde afspilning! Hvis du ser denne"
"besked, før du har klikket på stop-knappen, derefter på"
"bufferen løb ud (stigning ulSize ).");
if (WavePlayBegin (hwo, lpWaveHdr))
(
FPlaying = true;
Caption = "Playing ...";
Shape1-> Brush-> Color = clBlack;
Shape2-> Brush-> Color = clGreen;
)
)
)
//------------------------------------------------ ---------------------------

void __fastcall TForm1:: MMWomDone (TMessage & Msg)
(
Caption = "Done leger!"
WavePlayClose (hwo);
RecordButton-> Enabled = true;
StopButton-> Enabled = false;
Shape2-> Brush-> Color = clBlack;
)
//------------------------------------------------ ---------------------------

void __fastcall TForm1:: TrackBar1Change (TObject * Sender)
(
DWORD new_volume =
(DWORD) MAKEWPARAM (TrackBar1-> Max - TrackBar1-> Position,
TrackBar1-> Max - TrackBar1-> Position);
waveOutSetVolume ((HWAVEOUT) WAVE_MAPPER, new_volume);
)
//------------------------------------------------ ---------------------------gør en kende hvor hen til tilpasse denne kildekode til mit projekt eller kan vise mig en anden lyd steraming projekt kildekoden via USB?

thx ...

 
Jeg har brugt WaveLib at opdage DTMF-toner, der kommer ind i linjeindgang og derefter sende indlæg ud audio højttaler havn.Jeg brugte C # /. NET, men jeg er temmelig sikker på, at der er et C version.

Hvad er problemet med den kode, du bruger?
Du skal være meget påpasselig med oprettelsen af audio mixer og dens kontrol, eller du vil ikke høre noget.

 
i denne prøve, lydindgangen er fra lydkortet via mikrofon og den allokerede hukommelse er fyldt datas taget mikrofon og lydkort spiller den som en wave-fil, osv.
men jeg vil vælge den bølge input som USB-enhed.og kan de data, der tages med "FT_Read (ftHandle, RxBuffer, 1, & BytesReceived)" struktur.også RxBuffer omfatter skriftlige datas.bu, hvordan du tilføjer denne struktur i denne kode?

 

Welcome to EDABoard.com

Sponsor

Back
Top