freeMXF.org

Open discussion about freeMXF.org tools and MXF in general
It is currently Fri Nov 01, 2024 12:18 am
Board index » MXF Categories » freeMXF.org Tools



Post new topic Reply to topic  [ 21 posts ]  Go to page Previous  1, 2
Author
Search for:
Message

Offline
Board User

Joined: Thu Nov 19, 2009 3:07 pm
Posts: 12

Post Posted: Wed Jan 06, 2010 4:48 pm 
Top  
I got some questions about your pseudocode:

Code:
WriteWaveHeader()

For each sample of input data
{


Waht do you mean here? One Sample for all 8 channels or one sample for each channel?

Code:
    For channel is 1 .. 8
    {


Do you mean that i have to count up from channel 1 to channel 8 in a for-loop? For example

for(i = 0; i >= channel - 1; i++);

Code:
        Read 4 bytes from the source data
        If channel is less than or equal to number of channels
        {
            If data is 16 bits
                build a 16-bit word from source byte 2, top 4 bits,
                    followed by byte 3 bottom 4 bits, then byte 3 top 4 bits,
                    then byte 4 bottom 4 bits
           
            If data is 24 bits
                build a 24-bit word from source byte 1, top 4 bits,
                    followed by byte 2 bottom 4 bits, then byte 2, top 4 bits,
                    then byte 3 bottom 4 bits, then byte 3 top 4 bits,
                    then byte 4 bottom 4 bits

            Write the new value to the output file
        }
    }


I dont understand why i made a for-loop bevor and now a if-clause? Do i have to read the three first bits wich identifies the channel in each sample?

Greetings
Sebastian

 Profile  

Offline
Insider

Joined: Thu Apr 15, 2004 10:39 am
Posts: 198
Location: Scotland

Post Posted: Thu Jan 07, 2010 11:00 am 
Top  
m0nKeY wrote:
Waht do you mean here? One Sample for all 8 channels or one sample for each channel?
One sample in this case means for all channels, so for example if you have 48kHz audio with 4 channels, you will have 48000 samples per second, each will contain 4 audio values (one per channel) and 4 dummy values that will need to be discarded (because the wrapping is always 8 channel, no matter how many channels are used).

m0nKeY wrote:
Do you mean that i have to count up from channel 1 to channel 8 in a for-loop? For example

for(i = 0; i >= channel - 1; i++);
Yes (sort of), but I would rather do:

for(int chan = 1; chan <= 8; chan++)
{
// Code here
}

m0nKeY wrote:
I dont understand why i made a for-loop bevor and now a if-clause? Do i have to read the three first bits wich identifies the channel in each sample?
The outer loop executes for each set of audio samples (8 values per sample). The inner loop executes for each of the 8 values in the sample. Each of these values is either 16 or 24 bits and what you do with the data depends on that (the file will be all 16-bit or all 24-bit). There is no need to read the channel number from the sampe data because the loop variable of the inner loop will give you that. The header metadata will tell you whether the file is 16-bit or 24-bit and how many channels are active.

 Profile WWW  

Offline
Board User

Joined: Thu Nov 19, 2009 3:07 pm
Posts: 12

Post Posted: Thu Jan 07, 2010 4:45 pm 
Top  
Thanks,
now i understand what you mean. And i know you worked not alone on the standard. :) I think no one could do such a standard all alone. And you didn't not write the hole "the mxf book", but a chapter.

There is still one question about the structure of the audiostream. Let me do some calculation for example.

A one frame long stream has 48kHz / 25 = 1920 samples. Each sample has 8 channels, so there are 1920 samples * 8 channels = 15360 datawords.
One dataword is 4 bytes or 32 bits long, including the 24 - 16 bit PCM sample. So the total streamsize should be 61440 bytes. But the audiostream from my one frame long mxf file has a size of 61444 bytes. I dont know why there is a difference of 4 bytes?

And here is the code i wrote.

Code:
for(int i = 0; i < in.length()/32; i++) //streamsize in byte * 8 bit / 8 channels / 32 bits per word
      {
         for(int j = 1; j <= 8; j++)
         {            
            instream.read(data, 0, 4);
            if (j <= NumChannels)
            {
               short word = Create16BitPCMSample(data);
               outstream.write(ShortToByteArray(word));
            }
         }
      }


Code:
 private static short Create16BitPCMSample (byte[] data)
   {
      int buffer  = ((0xF0 & data[1]) << 8) | ((0x0F & data[2]) << 8) | (0xF0 & data[2]) | (0x0F & data[3]);
      short word = IntToShort(buffer);
      
      return word;
   }



Greetings
Sebastian

 Profile  

Offline
Insider

Joined: Thu Apr 15, 2004 10:39 am
Posts: 198
Location: Scotland

Post Posted: Fri Jan 08, 2010 9:51 am 
Top  
Ah, yes! You are right - there is a 4-byte header on each frame that can be skipped.

 Profile WWW  

Offline
Board User

Joined: Thu Nov 19, 2009 3:07 pm
Posts: 12

Post Posted: Fri Jan 08, 2010 11:02 am 
Top  
Hi,
because of my bad englisch i have to ask again. With frame you mean videoframe, so every 1920 audiosamples?

Greetings
Sebastian

 Profile  

Offline
Insider

Joined: Thu Apr 15, 2004 10:39 am
Posts: 198
Location: Scotland

Post Posted: Tue Jan 12, 2010 11:24 am 
Top  
Yes, every video frame, or I should have said each content package to be exact.

 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page Previous  1, 2

Jump to:  


Who is online

Users browsing this forum: No registered users and 3 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group :: Style based on FI Subice by phpBBservice.nl :: All times are UTC