It´s driving me nuts ... need some help! ;)

Please discuss general Delphi programming topics here.

It´s driving me nuts ... need some help! ;)

Postby Sonicfire1980 » July 25th, 2006, 3:36 am

Seriously, i´m searching for three days now on some information on HOW TO GET LOOP POINTS into wave files!! :roll:

I have a working code for saving WAV files, but for f**** sake i dont know how to make it store loop (cue) points!

I want to write an application that automatically stores a loop (one simple infinite loop) within a wav file, either at 25,50 or 75% ahead the sample start.

Can anyone *please* give me some hints or pointers into the right direction? I´m really getting mad :wink:

Thanks in advance!!
Sonicfire1980
Active Member
Active Member
 
Posts: 16
Joined: July 25th, 2006, 3:33 am
Location: berlin,germany

Postby Johnny_Bit » July 25th, 2006, 7:19 am

wav file spec does not permit it, neither accepts it, nor makes it possible. wav file except for header doesn't store any data or work codes
Johnny_Bit
VIP Member
VIP Member
 
Posts: 455
Joined: June 15th, 2003, 9:56 am

Postby Sonicfire1980 » July 25th, 2006, 4:16 pm

Of course i dont want to write data into the wav audio data itself - i meant the header :)
Sonicfire1980
Active Member
Active Member
 
Posts: 16
Joined: July 25th, 2006, 3:33 am
Location: berlin,germany

Postby P_G » July 31st, 2006, 11:24 am

Hi,

What format are you talking about? Is it the Windows PCM *.wav format?
In this case it's the RIFF-header. As far as I know this header doesn't support loop-points:

RIFF header (44 bytes):

4 Byte: ASCII-Sign for "RIFF"

4 Byte: Length of file (with Header) in Byte, decreased by 8

8 Byte: ASCII-Sign for "WAVEfmt_"

4 Byte: Hex 10 00 00 00

2 Byte: Format-Version: 1

2 Byte: Number of channels: 1 = Mono, 2 = Stereo

4 Byte: Sample frequency in Hz

4 Byte: Byte per second

2 Byte: Byte per sample (2 for 16 bits)

2 Byte: Bits per Sample

4 Byte: ASCII-Sign for "data"

4 Byte: Length of following data-field in byte

with best whishes, P_G
P_G
Senior Member
Senior Member
 
Posts: 51
Joined: June 14th, 2004, 11:13 am
Location: Germany

Postby Sonicfire1980 » July 31st, 2006, 11:45 am

Hi P_G,

it should support loop-points, since in all file-format documentations i´ve read there you can find information about a "smpl"-chunk which holds loop (cue)-point information (if any)... :)
Sonicfire1980
Active Member
Active Member
 
Posts: 16
Joined: July 25th, 2006, 3:33 am
Location: berlin,germany

Postby P_G » July 31st, 2006, 2:44 pm

Hi,
now I see... This information isn't stored in the header but is part of this smpl-certain chunk (you already mentioned it). So what exactly is your problem? This chunk is described here for example:
http://mediasrv.ns.ac.yu/extra/fileformat/sound/wav/wave.htm
So you have to create this chunk, not modify the header...

Best whishes,

P_G
P_G
Senior Member
Senior Member
 
Posts: 51
Joined: June 14th, 2004, 11:13 am
Location: Germany

Postby Sonicfire1980 » July 31st, 2006, 4:43 pm

Thank you very much! :D
If now i only would know how to describe / write this chunk ... :lol: :?
(I´m new to all this .. so forgive my ignorance) :wink:
Sonicfire1980
Active Member
Active Member
 
Posts: 16
Joined: July 25th, 2006, 3:33 am
Location: berlin,germany

Postby P_G » August 1st, 2006, 7:40 am

Hi Sonicfire1980,

Well, this chunk is just a record (Delphi-help: 'record'). The description of this record is mentioned in my last post. Just do something like this:

type TSMPL = record
chunkID : string;
chunkSize : Integer;
dwManufacturer : Integer;
dwProduct : Integer;
...
end;

Now you can easely fill this Chunks properties. Finally save header and chunks as a stream (*.wav). Someone correct me if I'm wrong.

Best whishes,

P_G
P_G
Senior Member
Senior Member
 
Posts: 51
Joined: June 14th, 2004, 11:13 am
Location: Germany

Postby Sonicfire1980 » August 1st, 2006, 11:23 am

Code: Select all
Type
  SmplLoop = record
    loopIdentifier: LongInt;
    loopType: LongInt;
    loopStart: LongInt;
    loopEnd: LongInt;
    loopFraction: LongInt;
    loopPlayCount: LongInt;
end;

Type
  SmplChunk = record
    ChunkID: Array[0..3] of Char; // 'smpl'
    ChunkSize: LongInt;
    Manufacturer: LongInt;
    Product: LongInt;
    SamplePeriod: LongInt;
    MIDIUnityNote: LongInt;
    MIDIPitchFraction: LongInt;
    SMPTEFormat: LongInt;
    SMPTEOffset: LongInt;
    SampleLoops: LongInt;
    SamplerData: LongInt;
    SampleLoop: SmplLoop;
end;


Thank you, yes - i tried it this way and finally i append the smpl chunk at the very end of the wav using: (F is my wav file)

Code: Select all
 
  Seek(F, FileSize(F));
  BlockWrite(F, WriteSmpl, SizeOf(WriteSmpl));


I have filled the chunk with data previously and this works very well, however there´s one strange thing ... directly at the start of the wav file after "RIFF" there must be something wrong with the bytesfollowing entry ... :) dont know why it´s always like 68 bytes too less :?
Sonicfire1980
Active Member
Active Member
 
Posts: 16
Joined: July 25th, 2006, 3:33 am
Location: berlin,germany

Postby P_G » August 1st, 2006, 2:14 pm

Hmmm,
I assume you are talking about the second entry of the header (Length of file)? In this case take a closer look at the code of your chunks (or data structures) to examine the problem. You possibly forgot to calculate the size of a certain property of one chunk?

Best whishes P_G
P_G
Senior Member
Senior Member
 
Posts: 51
Joined: June 14th, 2004, 11:13 am
Location: Germany

Postby Sonicfire1980 » August 2nd, 2006, 12:13 am

Thanks for your help P_G! :) I fixed it, and now it works fine.

However (as i already stated) - i´m new to all this, so forgive me, but i have another problem: I have big trouble converting all the dozens of data types between each other... e.g smallint <> longint ... and so on...

e.g:

bufoffset is smallint
header.databytes is longint
---
bufoffset := header.databytes; <- wont work
for i:=0 to bufoffset do <- i need smallint here...

:twisted: oh hell, it´s driving me crazy :lol: :?
Sonicfire1980
Active Member
Active Member
 
Posts: 16
Joined: July 25th, 2006, 3:33 am
Location: berlin,germany

Postby Sonicfire1980 » August 2nd, 2006, 12:45 pm

May i ask for help again?

Another confusing thing :

Code: Select all
LoopBuffer: arry of SmallInt;
SetLength(LoopBuffer, Header.DataBytes);
LoopBuffer := 0;


(...)

Code: Select all
BlockWrite(F, LoopBuffer, Length(LoopBuffer));


..raises EInOutError 1784 ... (The supplied user buffer is not valid for the requested operation) :shock:


Again, i wonder why. BlockWrite needs Integer for Count, Length(LoopBuffer) DOES deliver an Integer. I also checked it, Length(LoopBuffer) results in something like e.g. 203198 Bytes. So everything should be okay.
Sonicfire1980
Active Member
Active Member
 
Posts: 16
Joined: July 25th, 2006, 3:33 am
Location: berlin,germany

Postby Johnny_Bit » August 2nd, 2006, 3:05 pm

tru using SizeOf
Johnny_Bit
VIP Member
VIP Member
 
Posts: 455
Joined: June 15th, 2003, 9:56 am

Postby Sonicfire1980 » August 2nd, 2006, 3:25 pm

Johnny_Bit wrote:tru using SizeOf


thanks, but SizeOf gives me only a value of "4" :? Perhaps because im passing an array to it, not a type...
Sonicfire1980
Active Member
Active Member
 
Posts: 16
Joined: July 25th, 2006, 3:33 am
Location: berlin,germany

Postby Sonicfire1980 » August 2nd, 2006, 6:44 pm

Okay i think i found the error ...
I changed it into:
Code: Select all
BlockWrite(F, LoopBuffer[0], Header.DataBytes);


Unfortunately it does now write crap into the wav file: :lol: :x http://www.prodyon-virtual-gear.com/annoying.wav

I´m lost - i really dont know whats wrong here :roll:
Sonicfire1980
Active Member
Active Member
 
Posts: 16
Joined: July 25th, 2006, 3:33 am
Location: berlin,germany

Next

Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 3 guests

cron