2017년 2월 5일 일요일

Bass.dll 을 이용한 mp3 연속 플레이하기

폼생성시 초기화 합니다.
mp3 파일은 sqlite 파일로 되어 있어 CheckListBox로 필요한 것만 읽어 옮니다.
트랙바 부분은 아래에 설명

procedure TForm1.FormCreate(Sender: TObject);
var istr: string;
begin
TrackBar2.OnMouseUp := TBMouseUp;
TrackBar2.OnMouseDown := TBMouseDown;
ZConnection1.Connect;
ZTable1.Open;
// check the correct BASS was loaded
if (HIWORD(BASS_GetVersion) <> BASSVERSION) then begin
MessageBox(0,'An incorrect version',nil,MB_ICONERROR);
Halt;
end;
iPause:= False;
// Initialize audio - default device, 44100hz, stereo, 16 bits
if not BASS_Init(-1, 44100, 0, Handle, nil) then
Error('Error initializing audio!');
end;

시작버튼

procedure TForm1.btPlayClick(Sender: TObject);
var
iCoor: TPoint;
begin
Timer1.Enabled:= False;
iPause:= False;
btRestart.Caption:= 'Pause';
BASS_ChannelStop(iStream);
if CheckListBox1.items.Count = 0 then exit;
// Play the stream (continuing from current position)
if CheckListBox1.ItemIndex >= 0 then begin
iCount:= 0;
playmp3(CheckListBox1.ItemIndex);
TrackBar2.Max:= BASS_ChannelGetLength(iStream, BASS_POS_BYTE);
Timer1.Enabled:= True;
end;
btDate.Caption:= DBEdit2.Text;
end;

Bass Stream 을 생성(파일 경로로); istream: integer로 전역 선언

procedure TForm1.playmp3(idx: integer);
var f: PChar;
begin
if CheckListBox1.checked[idx]= True then exit;

f:= PChar(CheckListBox1.items[idx]);
iStream:= BASS_StreamCreateFile(False, f, 0, 0, 0 or BASS_UNICODE);
//BASS_ChannelSetAttribute(iStream, BASS_ATTRIB_PAN, (Random(201) - 100) / 100);
//BASS_ChannelSetAttribute(iStream, BASS_ATTRIB_VOL, 0.8);
if not BASS_ChannelPlay(iStream, True) then Error('Error playing stream!');
end;

타이머가 돌아가면서 하나의 mp3 가 끝났는지 확인하고 반복하고나 다음 mp3 연주

procedure TForm1.Timer1Timer(Sender: TObject);
begin
if BASS_GetCPU < 0.00001 then begin
inc(iCount);
if iCount >= spinedit1.Value then begin
iCount:= 0;
CheckListBox1.ItemIndex:= CheckListBox1.ItemIndex + 1;
CheckListBox1.Tag:= CheckListBox1.Tag + 1;
ZQuery1.Next;
if CheckListBox1.Tag <> CheckListBox1.ItemIndex then begin
CheckListBox1.ItemIndex:= 0;
CheckListBox1.Tag:= 0;
iCount:= 0;
Zquery1.First;
Timer1.Enabled:= False;
end else
//
end;
Timer1.Enabled:= False;
if CheckListBox1.Checked[CheckListBox1.ItemIndex]= False then
Delay(TrackBar1.Position*100);
playmp3(CheckListBox1.ItemIndex);
TrackBar2.Max:= BASS_ChannelGetLength(iStream, BASS_POS_BYTE);
Timer1.Enabled:= True;
end;
TrackBar2.Position := BASS_ChannelGetPosition(iStream, BASS_POS_BYTE);
end;

tensorflow gpu 사용하기에서

 tensorflow 설치시 주의해야 한다. # Anything above 2.10 is not supported on the GPU on Windows Native python - m pip install "tensorflow<2.11...