Форум: "Система";
Текущий архив: 2003.05.22;
Скачать: [xml.tar.bz2];
ВнизВход звуковой карты. Найти похожие ветки
← →
Tolyan (2003-03-24 11:10) [0]Привет всем. Может кто-нибудь подскажет, как читать данные со входа звуковой.
Я ее хочу использовать как вход АЦП. Хотелось бы непросто в какой-нибудь .wav
файл а потом из него (надо ещё и формат .wav знать), а напрямую байтики в соответствии с амплитудой в real time. Может подскажете куда сунуться по этому поводу.
Буду очень благодарен.
← →
Sergo (2003-03-24 14:49) [1]MSDN + FFT
вот небольшой пример:
unit Unit1;
interface
uses
..., MMSystem; // Don"t forget about it!
TForm1 = class(TForm)
//...
procedure StartWaveIn;
procedure OnWaveIn(var Msg : TMessage); message MM_WIM_DATA;
procedure StopWaveIn;
//...
private
{ Private declarations }
public
{ Public declarations }
end;
var
wave_in : HWAVEIN;
buffer_handle_0 : THANDLE;
buffer_handle_1 : THANDLE;
buffer_0 : pointer; // Audio data buffer
buffer_1 : pointer; // Audio data buffer
buffer_header_0 : pWAVEHDR; // Defines the header used to identify a
waveform-audio buffer
buffer_header_1 : pWAVEHDR;
buffer_length : DWORD;
OnceExecuted : boolean;
implementation
{$R *.DFM}
//...
Procedure TForm1.StartWaveIn;
var
result : MMResult;
header : pWAVEFORMATEX; // Defines the format of waveform-audio data.
const
buffer_size = 512;
begin
if 0 = waveInGetNumDevs then exit; // No Audio input devices are present
new(header);
with header^ do
begin
wFormatTag := WAVE_FORMAT_PCM;
nChannels := 1; // Stereo input
nSamplesPerSec := 22050; // 22 kHz
wBitsPerSample := 8; // 8 bit
nBlockAlign := nChannels*wBitsPerSample shr 3;
nAvgBytesPerSec := nSamplesPerSec*nBlockAlign;
cbSize := 0; // No additional information
end;
// Check if the wave-in device is capable to read data in the format
specified
result := waveInOpen(@wave_in, WAVE_MAPPER, header, Form1.Handle, 0,
CALLBACK_WINDOW);
if result<>0then exit; // Something is going wrong
buffer_length := header.nChannels*(header.wBitsPerSample shr 3)*buffer_size;
buffer_handle_0 := GlobalAlloc(GMEM_MOVEABLE and GMEM_SHARE, buffer_length);
buffer_handle_1 := GlobalAlloc(GMEM_MOVEABLE and GMEM_SHARE, buffer_length);
buffer_0 := GlobalLock(buffer_handle_0);
buffer_1 := GlobalLock(buffer_handle_1);
new(buffer_header_0);
with buffer_header_0^ do
begin
lpData := buffer_0;
dwBufferLength := buffer_length;
dwFlags := WHDR_BEGINLOOP;
end;
result := waveInPrepareHeader(wave_in, buffer_header_0,
sizeof(buffer_header_0^));
result := waveInAddBuffer(wave_in, buffer_header_0,
sizeof(buffer_header_0^));
if result<>0then exit; // Something is going wrong
new(buffer_header_1);
with buffer_header_1^ do
begin
lpData := buffer_1;
dwBufferLength := buffer_length;
dwFlags := WHDR_ENDLOOP;
end;
result := waveInPrepareHeader(wave_in, buffer_header_1,
sizeof(buffer_header_1^));
result := waveInAddBuffer(wave_in, buffer_header_1,
sizeof(buffer_header_1^));
result := waveInStart(wave_in); // Start recording
dispose(header)
end;
procedure TForm1.OnWaveIn;
var
WaveHeader : pWAVEHDR;
result : MMResult;
begin
WaveHeader := pointer(Msg.lParam);
// Process data
if DataProcessed then
begin
Move(WaveHeader^.lpData^, ba, 512);
DataProcessed := false;
end;
result := waveInAddBuffer(wave_in, WaveHeader, SizeOf(WaveHeader^))
end;
procedure TForm1.StopWaveIn;
var
result : MMResult;
begin
if 0 = waveInGetNumDevs then exit; // No Audio input devices are present
result := waveInReset(wave_in);
result := waveInUnPrepareHeader(wave_in, buffer_header_0,
sizeof(buffer_header_0^));
result := waveInUnPrepareHeader(wave_in, buffer_header_1,
sizeof(buffer_header_1^));
result := waveInClose(wave_in);
GlobalUnlock(buffer_handle_0);
GlobalUnlock(buffer_handle_1);
GlobalFree(buffer_handle_0);
GlobalFree(buffer_handle_1);
dispose(buffer_header_0);
dispose(buffer_header_1)
end;
//...
end.
Страницы: 1 вся ветка
Форум: "Система";
Текущий архив: 2003.05.22;
Скачать: [xml.tar.bz2];
Память: 0.46 MB
Время: 0.008 c