mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-15 20:09:20 +02:00
* Created some helper functions for vorbis and a52
* Working madopenal samples with mp3, ogg and ac3 support git-svn-id: trunk@4685 -
This commit is contained in:
parent
2c9ccaf4b3
commit
1870c41c40
@ -492,18 +492,20 @@ var
|
|||||||
begin
|
begin
|
||||||
ofs := 0;
|
ofs := 0;
|
||||||
num := length;
|
num := length;
|
||||||
|
|
||||||
while num > 0 do
|
while num > 0 do
|
||||||
begin
|
begin
|
||||||
len := PtrInt(decoder^.inbuf_ptr) - PtrInt(@decoder^.inbuf);
|
len := PtrInt(decoder^.inbuf_ptr) - PtrInt(@decoder^.inbuf);
|
||||||
|
|
||||||
if decoder^.frame_size = 0 then
|
if decoder^.frame_size = 0 then
|
||||||
begin
|
begin
|
||||||
(* no header seen : find one. We need at least 7 bytes to parse it *)
|
(* no header seen : find one. We need at least 7 bytes to parse it *)
|
||||||
len := HEADER_SIZE - len;
|
//WriteLn('no header seen (', len, ')');
|
||||||
{if len > buf_size then
|
|
||||||
len := buf_size;}
|
|
||||||
|
|
||||||
|
len := HEADER_SIZE - len;
|
||||||
if decoder^.read(decoder^.inbuf_ptr, 1, len, decoder^.datasource) <> len then
|
if decoder^.read(decoder^.inbuf_ptr, 1, len, decoder^.datasource) <> len then
|
||||||
Exit(ofs);
|
Exit(ofs);
|
||||||
|
|
||||||
Inc(decoder^.inbuf_ptr, len);
|
Inc(decoder^.inbuf_ptr, len);
|
||||||
|
|
||||||
if PtrInt(decoder^.inbuf_ptr) - PtrInt(@decoder^.inbuf) = HEADER_SIZE then
|
if PtrInt(decoder^.inbuf_ptr) - PtrInt(@decoder^.inbuf) = HEADER_SIZE then
|
||||||
@ -516,6 +518,7 @@ begin
|
|||||||
Dec(decoder^.inbuf_ptr);
|
Dec(decoder^.inbuf_ptr);
|
||||||
end else begin
|
end else begin
|
||||||
decoder^.frame_size := len;
|
decoder^.frame_size := len;
|
||||||
|
|
||||||
(* update codec info *)
|
(* update codec info *)
|
||||||
decoder^.sample_rate := sample_rate;
|
decoder^.sample_rate := sample_rate;
|
||||||
decoder^.bit_rate := bit_rate;
|
decoder^.bit_rate := bit_rate;
|
||||||
@ -523,28 +526,32 @@ begin
|
|||||||
if decoder^.flags and A52_LFE <> 0 then
|
if decoder^.flags and A52_LFE <> 0 then
|
||||||
Inc(decoder^.channels);
|
Inc(decoder^.channels);
|
||||||
|
|
||||||
|
{WriteLn(' frame_size : ', decoder^.frame_size);
|
||||||
|
WriteLn(' sample_rate : ', sample_rate);
|
||||||
|
WriteLn(' bit_rate : ', bit_rate);
|
||||||
|
WriteLn(' channels : ', decoder^.channels);}
|
||||||
|
|
||||||
// test against user channel settings (wrong here)
|
// test against user channel settings (wrong here)
|
||||||
{if decoder^.req_chan = 0 then
|
{if decoder^.req_chan = 0 then
|
||||||
decoder^.req_chan := decoder^.channels else
|
decoder^.req_chan := decoder^.channels else
|
||||||
if decoder^.channels < decoder^.req_chan then
|
if decoder^.channels < decoder^.req_chan then
|
||||||
decoder^.req_chan := decoder^.channels;}
|
decoder^.req_chan := decoder^.channels;}
|
||||||
end;
|
end;
|
||||||
end;
|
end else
|
||||||
end else
|
WriteLn('BUG!!!!');
|
||||||
|
end else begin
|
||||||
if len < decoder^.frame_size then
|
if len < decoder^.frame_size then
|
||||||
begin
|
begin
|
||||||
len := decoder^.frame_size - len;
|
len := decoder^.frame_size - len;
|
||||||
{if len > buf_size then
|
|
||||||
len := buf_size;}
|
|
||||||
|
|
||||||
if decoder^.read(decoder^.inbuf_ptr, 1, len, decoder^.datasource) <> len then
|
if decoder^.read(decoder^.inbuf_ptr, 1, len, decoder^.datasource) <> len then
|
||||||
Exit(ofs);
|
Exit(ofs);
|
||||||
|
|
||||||
Inc(decoder^.inbuf_ptr, len);
|
Inc(decoder^.inbuf_ptr, len);
|
||||||
end else begin
|
end else begin
|
||||||
flags := A52_STEREO;//decoder^.flags;
|
flags := A52_STEREO;//decoder^.flags;
|
||||||
level := 1;
|
level := High(Smallint)-30;
|
||||||
|
|
||||||
if a52_frame(decoder^.state, @decoder^.inbuf, flags, level, 384) <> 0 then
|
if a52_frame(decoder^.state, @decoder^.inbuf, flags, level, 0) <> 0 then
|
||||||
begin
|
begin
|
||||||
decoder^.inbuf_ptr := @decoder^.inbuf;
|
decoder^.inbuf_ptr := @decoder^.inbuf;
|
||||||
decoder^.frame_size := 0;
|
decoder^.frame_size := 0;
|
||||||
@ -556,7 +563,7 @@ begin
|
|||||||
if a52_block(decoder^.state) <> 0 then
|
if a52_block(decoder^.state) <> 0 then
|
||||||
Exit(-1);
|
Exit(-1);
|
||||||
|
|
||||||
float_to_int(decoder^.samples, pointer(PtrInt(buffer) + Ofs + 2{channels}*i*256*2{sample_size}), 2{channels});
|
float_to_int(decoder^.samples, pointer(PtrInt(buffer) + ofs + 2{channels}*i*256*2{sample_size}), 2{channels});
|
||||||
end;
|
end;
|
||||||
|
|
||||||
decoder^.inbuf_ptr := @decoder^.inbuf;
|
decoder^.inbuf_ptr := @decoder^.inbuf;
|
||||||
@ -565,6 +572,7 @@ begin
|
|||||||
ofs := ofs + 2{channels}*(6*256){samples}*2{sample_size};
|
ofs := ofs + 2{channels}*(6*256){samples}*2{sample_size};
|
||||||
num := num - 2{channels}*(6*256){samples}*2{sample_size};
|
num := num - 2{channels}*(6*256){samples}*2{sample_size};
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Result := ofs;
|
Result := ofs;
|
||||||
|
@ -374,6 +374,14 @@ function ov_halfrate(var vf: OggVorbis_File; flag: cint): cint; cdecl; external
|
|||||||
function ov_halfrate_p(var vf: OggVorbis_File): cint; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
|
function ov_halfrate_p(var vf: OggVorbis_File): cint; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
Developer of the A52 helpers for FreePascal
|
||||||
|
Copyright (C) 2006 by Ivo Steinmann
|
||||||
|
}
|
||||||
|
|
||||||
|
function ov_read_ext(var vf: OggVorbis_File; buffer: pointer; length: cint; bigendianp: cbool; word: cint; sgned: cbool): clong;
|
||||||
|
|
||||||
|
|
||||||
(***********************************************************************)
|
(***********************************************************************)
|
||||||
(* Header : vorbisenc.h *)
|
(* Header : vorbisenc.h *)
|
||||||
(***********************************************************************)
|
(***********************************************************************)
|
||||||
@ -416,5 +424,33 @@ function vorbis_encode_ctl(var vi: vorbis_info; number: cint; arg: pointer): cin
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
function ov_read_ext(var vf: OggVorbis_File; buffer: pointer; length: cint; bigendianp: cbool; word: cint; sgned: cbool): clong;
|
||||||
|
var
|
||||||
|
ofs: cint;
|
||||||
|
Num: cint;
|
||||||
|
Res: cint;
|
||||||
|
begin
|
||||||
|
{if length mod 4 <> 0 then
|
||||||
|
Exit(0);}
|
||||||
|
|
||||||
|
ofs := 0;
|
||||||
|
num := length;
|
||||||
|
|
||||||
|
while num > 0 do
|
||||||
|
begin
|
||||||
|
res := ov_read(vf, pointer(ptrint(buffer) + ofs), num, bigendianp, word, sgned, nil);
|
||||||
|
if res <= 0 then
|
||||||
|
Exit(res);
|
||||||
|
|
||||||
|
if res = 0 then
|
||||||
|
Break;
|
||||||
|
|
||||||
|
ofs := ofs + res;
|
||||||
|
num := num - res;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Result := ofs;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ var
|
|||||||
Remaining : Integer;
|
Remaining : Integer;
|
||||||
ReadStart : Pointer;
|
ReadStart : Pointer;
|
||||||
ReadSize : Integer;
|
ReadSize : Integer;
|
||||||
Output : PByte;
|
Output : PSmallint;
|
||||||
begin
|
begin
|
||||||
Ofs := 0;
|
Ofs := 0;
|
||||||
Num := Count;
|
Num := Count;
|
||||||
@ -130,7 +130,6 @@ end;
|
|||||||
|
|
||||||
function ogg_seek_func(datasource: pointer; offset: ogg_int64_t; whence: cint): cint; cdecl;
|
function ogg_seek_func(datasource: pointer; offset: ogg_int64_t; whence: cint): cint; cdecl;
|
||||||
begin
|
begin
|
||||||
WriteLn('seek');
|
|
||||||
case whence of
|
case whence of
|
||||||
{SEEK_SET} 0: TStream(datasource).Seek(offset, soFromBeginning);
|
{SEEK_SET} 0: TStream(datasource).Seek(offset, soFromBeginning);
|
||||||
{SEEK_CUR} 1: TStream(datasource).Seek(offset, soFromCurrent);
|
{SEEK_CUR} 1: TStream(datasource).Seek(offset, soFromCurrent);
|
||||||
@ -157,27 +156,12 @@ end;}
|
|||||||
|
|
||||||
function ogg_read(const Buffer: Pointer; const Count: Longword): Longword;
|
function ogg_read(const Buffer: Pointer; const Count: Longword): Longword;
|
||||||
var
|
var
|
||||||
Ofs: Longword;
|
Res: clong;
|
||||||
Num: Longword;
|
|
||||||
Res: Integer;
|
|
||||||
begin
|
begin
|
||||||
Ofs := 0;
|
Res := ov_read_ext(ogg_vorbis, Buffer, Count, false, 2, true);
|
||||||
Num := Count;
|
if Res < 0 then
|
||||||
|
Exit(0) else
|
||||||
while Num > 0 do
|
Result := Res;
|
||||||
begin
|
|
||||||
Res := ov_read(ogg_vorbis, Pointer(PtrUInt(Buffer) + Ofs), Num, False, 2, True, nil);
|
|
||||||
if Res < 0 then
|
|
||||||
Exit(0);
|
|
||||||
|
|
||||||
if Res = 0 then
|
|
||||||
Break;
|
|
||||||
|
|
||||||
Ofs := Ofs + Longword(Res);
|
|
||||||
Num := Num - Longword(Res);
|
|
||||||
end;
|
|
||||||
|
|
||||||
Result := Ofs;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -286,14 +270,15 @@ var
|
|||||||
ov: pvorbis_info;
|
ov: pvorbis_info;
|
||||||
begin
|
begin
|
||||||
// define codec
|
// define codec
|
||||||
{WriteLn('Define codec');
|
WriteLn('Define codec');
|
||||||
Writeln(' (1) mp3');
|
Writeln(' (1) mp3');
|
||||||
Writeln(' (2) ogg');
|
Writeln(' (2) ogg');
|
||||||
|
Writeln(' (3) ac3');
|
||||||
Write('Enter: '); ReadLn(codec);
|
Write('Enter: '); ReadLn(codec);
|
||||||
Write('File: '); ReadLn(Filename);}
|
Write('File: '); ReadLn(Filename);
|
||||||
|
|
||||||
codec := 1;
|
{codec := 1;
|
||||||
Filename := 'test.mp3';
|
Filename := 'test.mp3';}
|
||||||
|
|
||||||
|
|
||||||
// load file
|
// load file
|
||||||
@ -336,7 +321,7 @@ begin
|
|||||||
a52_decoder := a52_decoder_init(0, source, @ogg_read_func, @ogg_seek_func, @ogg_close_func, @ogg_tell_func);
|
a52_decoder := a52_decoder_init(0, source, @ogg_read_func, @ogg_seek_func, @ogg_close_func, @ogg_tell_func);
|
||||||
codec_bs := 2{channels}*1536*2{sample_size};
|
codec_bs := 2{channels}*1536*2{sample_size};
|
||||||
codec_read := @a52_read;
|
codec_read := @a52_read;
|
||||||
codec_rate := 44100;
|
codec_rate := 48000;
|
||||||
codec_chan := 2;
|
codec_chan := 2;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user