Wave Audio no sound o/p

Please post bug reports, feature requests, or any question regarding the DELPHI AREA products here.

Wave Audio no sound o/p

Postby Paracom » May 14th, 2005, 6:48 pm

Hi,
I can not get TAudioPlayer to produce any sound output

i am setting the Twave.loadfromfile('c:\testwave.wav');

If i use the built in dialog to select a wave file i can hear it ok when i press
play.

when i set TAudioPlayer active to true i hear no sound
i have stepped thru source code on debug and waveOutOpen is being set ok, it appears that no data is being sent to the output device when active is set to true,

I have a different audio comp that uses waveOutOpen as above
but to actually reproduce the sound it makes a call waveOutWrite,
i can find no similar call in Wave audio comps

Delphi 5 pro Xp svr pack 2

:cry:

Any feedback appreciated.
Paracom
Member
Member
 
Posts: 3
Joined: May 14th, 2005, 6:38 pm

Postby Kambiz » May 14th, 2005, 8:31 pm

Hi,

Definitely there's something wrong in your code. Please post your code includeing the dfm file here.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Code as requested for above

Postby Paracom » May 14th, 2005, 9:49 pm

Code: Select all
unit testwav;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls,
  Forms, Dialogs, Buttons, WaveIO, WaveOut, WavePlayers;

type
  TForm1 = class(TForm)
    AudioPlayer1: TAudioPlayer;
    loadfilebutton: TSpeedButton;
    playbutton: TSpeedButton;
    procedure loadfilebuttonClick(Sender: TObject);
    procedure playbuttonClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.loadfilebuttonClick(Sender: TObject);
begin
AudioPlayer1.Active := false;
AudioPlayer1.Wave.LoadFromFile('c:\testwave.wav');
// this file exists and will play ok if use property editor for wave
// was recorded with soundrecorder, plays back ok with that app aswell
end;

procedure TForm1.playbuttonClick(Sender: TObject);
begin
AudioPlayer1.Active := true;
// no sound heard
end;

end.


Code: Select all
object Form1: TForm1
  Left = 269
  Top = 147
  Width = 215
  Height = 108
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object loadfilebutton: TSpeedButton
    Left = 11
    Top = 41
    Width = 84
    Height = 22
    Caption = 'Load'
    OnClick = loadfilebuttonClick
  end
  object playbutton: TSpeedButton
    Left = 111
    Top = 41
    Width = 84
    Height = 22
    Caption = 'Play'
    OnClick = playbuttonClick
  end
  object AudioPlayer1: TAudioPlayer
    Left = 8
    Top = 4
  end
end


:?:

regards dave.
Paracom
Member
Member
 
Posts: 3
Joined: May 14th, 2005, 6:38 pm

this code work ok for soundfile above

Postby Paracom » May 14th, 2005, 10:02 pm

Code snippet from a different audio comp, that uses
multimedia api as does Wave Audio.

------------------------------------------

procedure TForm1.SpeedButton1Click(Sender: TObject);
var
tempstrm : Tfilestream;
begin
tempstrm := Tfilestream.Create('c:\testwave.wav',fmOpenRead);
tempstrm.Position := 0;
WavePlayer.Source := tempstrm;
WavePlayer.Loops := 2;
WavePlayer.Play;
etc.......

----->

function TWavePlayer.Play:boolean;
var WaveInfo:PWaveFormatEx;
i:integer;
res:MMRESULT;

begin

if FState = wpPlaying then
begin
result:=false;
exit;
end;

if FState = wpPaused then
begin
result:=Pause;
exit;
end;

WaveInfo:=nil; //keeps compiler quiet
try
WaveInfo:=LoadWaveFile;
if WaveInfo = nil then WaveInfo:=LoadMPEG1File;
if WaveInfo = nil then Abort;

FLoopsToPlay:=FDesiredLoops-1; //One loop will be always played
FPlayingBufferCount:=0; //None is actually being played

//Allocate Buffers
with WaveInfo^ do
FBufferSize:=nBlockAlign*nSamplesPerSec shr 6; //Like div 64
//BlocksInBuffer;
for i:=0 to 7 do
begin
getmem(FBuffers[i].lpData, FBufferSize);
FBuffers[i].dwLoops:=1;
FBuffers[i].dwUser:=i;
end;

//Open the WAVE_MAPPER,
res:=waveOutOpen(@FDevice, WAVE_MAPPER, WaveInfo,
FWnd,
cardinal(Self),
CALLBACK_WINDOW or WAVE_ALLOWSYNC);
if res <> MMSYSERR_NOERROR then
raise EWPlayer.Create('MM System Error: '+inttostr(res));
freemem(WaveInfo);

//Seek the first data byte
FSource.Position:=FDataStart;
//load buffers
for i:=0 to 7 do
LoadBuffer(i);

//and play them.
FState:=wpPlaying; //Mark desired state
for i:=0 to 7 do
if FBuffers[i].dwBufferLength <> 0 then
waveOutWrite(FDevice, @FBuffers[i], WaveHdrSize);

// sound produced ok above .... how do you do 'waveOutWrite'
// or by alternate method ???

result:=true;
except
FState:=wpStopped;

freemem(WaveInfo);
for i:=0 to 7 do
freemem(FBuffers[i].lpData);
result:=false;

if FBeepAtLeast then Windows.MessageBeep(MB_ICONQUESTION);

FState:=wpStopped;
end;
end;


Regards dave. Paracom Systems

ps on previous code Taudioplayer has all default values as when it is
first dropped on a form.
Paracom
Member
Member
 
Posts: 3
Joined: May 14th, 2005, 6:38 pm

Postby Kambiz » May 23rd, 2005, 7:43 am

Sounds strange!

What format is the wave file? Could you please send me the wave file via email?
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm


Return to DELPHI AREA Products

Who is online

Users browsing this forum: No registered users and 1 guest

cron