Line 2... |
Line 2... |
-- Project : VHDL WAVE files
|
-- Project : VHDL WAVE files
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
-- File : Wavefiles-p.vhd
|
-- File : Wavefiles-p.vhd
|
-- Author : Alexander Lindert <alexander_lindert at gmx.at>
|
-- Author : Alexander Lindert <alexander_lindert at gmx.at>
|
-- Created : 2008-08-19
|
-- Created : 2008-08-19
|
-- Last update: 2008-08-23
|
-- Last update: 2008-09-19
|
-- Platform :
|
-- Platform :
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
-- Description: This package can read or write VHDL signals from or to wave files.
|
-- Description: This package can read or write VHDL signals from or to wave files.
|
-- There are no restriction for the numbers of channels and the sampling
|
-- There are no restriction for the numbers of channels and the sampling
|
-- frequences because Octave and Matlab can read them in every configuration.
|
-- frequences because Octave and Matlab can read them in every configuration.
|
Line 99... |
Line 99... |
return Ret;
|
return Ret;
|
end;
|
end;
|
|
|
function ReadDword(file WaveFileHandle : aFileHandle) return integer is
|
function ReadDword(file WaveFileHandle : aFileHandle) return integer is
|
variable Ret : integer := 0;
|
variable Ret : integer := 0;
|
variable temp : natural := 0;
|
|
variable ch : character;
|
variable ch : character;
|
begin
|
begin
|
for i in 0 to 3 loop
|
for i in 0 to 3 loop
|
read(WaveFileHandle, ch);
|
read(WaveFileHandle, ch);
|
temp := natural(character'pos(ch));
|
Ret := Ret + character'pos(ch)*2**(8*i);
|
Ret := Ret + temp*2**(8*i);
|
|
end loop;
|
end loop;
|
return Ret;
|
return Ret;
|
end;
|
end;
|
|
|
function ReadWord(file WaveFileHandle : aFileHandle) return integer is
|
function ReadWord(file WaveFileHandle : aFileHandle) return integer is
|
Line 159... |
Line 157... |
assert(ReadString(WaveFileHandle, "data"))
|
assert(ReadString(WaveFileHandle, "data"))
|
report "The file " & FileName & " is not a wave file!" severity failure;
|
report "The file " & FileName & " is not a wave file!" severity failure;
|
FileInfo.DataSize := ReadDword(WaveFileHandle);
|
FileInfo.DataSize := ReadDword(WaveFileHandle);
|
end;
|
end;
|
|
|
|
|
|
function ReadSignedDword(file WaveFileHandle : aFileHandle) return integer is
|
|
variable Ret : integer := 0;
|
|
variable ch : character;
|
|
begin
|
|
for i in 0 to 3 loop
|
|
read(WaveFileHandle, ch);
|
|
Ret := Ret + character'pos(ch)*2**(8*i);
|
|
end loop;
|
|
return Ret;
|
|
end;
|
|
|
|
function ReadSignedWord(file WaveFileHandle : aFileHandle) return integer is
|
|
variable Ret : integer := 0;
|
|
variable ch : character;
|
|
begin
|
|
for i in 0 to 1 loop
|
|
read(WaveFileHandle, ch);
|
|
|
|
Ret := Ret + character'pos(ch)*2**(8*i);
|
|
end loop;
|
|
if Ret >= 2**15 then
|
|
Ret := Ret - 2**16;
|
|
end if;
|
|
return Ret;
|
|
end;
|
|
|
|
function ReadSignedByte(file WaveFileHandle : aFileHandle) return integer is
|
|
variable Ret : integer := 0;
|
|
variable ch : character;
|
|
begin
|
|
read(WaveFileHandle, ch);
|
|
Ret := character'pos(ch);
|
|
if Ret >= 2**7 then
|
|
Ret := Ret - 2**8;
|
|
end if;
|
|
return Ret;
|
|
end;
|
|
|
procedure ReadSample(file WaveFileHandle : aFileHandle;
|
procedure ReadSample(file WaveFileHandle : aFileHandle;
|
variable Sample : out integer;
|
variable Sample : out integer;
|
variable RemainingData : inout natural;
|
variable RemainingData : inout natural;
|
constant DataTyp : aWaveDataTyp) is
|
constant DataTyp : aWaveDataTyp) is
|
variable Ret : integer := 0;
|
variable Ret : integer := 0;
|
Line 175... |
Line 212... |
report "End of file reached!" severity note;
|
report "End of file reached!" severity note;
|
end if;
|
end if;
|
else
|
else
|
case DataTyp is
|
case DataTyp is
|
when PCM8 =>
|
when PCM8 =>
|
read(WaveFileHandle, ch);
|
Ret := ReadSignedByte(WaveFileHandle);
|
Ret := character'pos(ch);
|
|
RemainingData := RemainingData-1;
|
RemainingData := RemainingData-1;
|
when PCM16LE =>
|
when PCM16LE =>
|
Ret := ReadWord(WaveFileHandle);
|
Ret := ReadSignedWord(WaveFileHandle);
|
RemainingData := RemainingData-2;
|
RemainingData := RemainingData-2;
|
when PCM32LE =>
|
when PCM32LE =>
|
Ret := ReadDword(WaveFileHandle);
|
Ret := ReadSignedDword(WaveFileHandle);
|
RemainingData := RemainingData-4;
|
RemainingData := RemainingData-4;
|
end case;
|
end case;
|
end if;
|
end if;
|
Sample := Ret;
|
Sample := Ret;
|
end;
|
end;
|