void WaveWriter::createHeader()
{
	std::cout<<"Creating Header...";
	const unsigned int num_channels = 1;
	const unsigned int bytes_per_sample = 4;
	const unsigned int chunk_length = SAMPLE_RATE * PLAY_LENGTH * bytes_per_sample;

	write4CC('RIFF', 0); //File description header
	write4Bytes(4 + 26 + 12 + 8 + chunk_length, 4); //size of file
	write4CC('WAVE', 8); //WAV description header
	write4CC('fmt ', 12); //Format description header
	write4Bytes(18, 16); //Size of Wave section chunck
	write2Bytes(0x0003 ,20); //WAVE type format
	write2Bytes(num_channels, 22); //number of channels
	write4Bytes(SAMPLE_RATE, 24); //saples per second
	write4Bytes(SAMPLE_RATE * bytes_per_sample * num_channels, 28); // bytes oer second
	write2Bytes(num_channels * bytes_per_sample, 32); //block alignment
	write2Bytes(bytes_per_sample * 8, 34); //bits per sample
	write2Bytes(0, 36); 
	write4CC('fact', 38);
	write4Bytes(4, 42);
	write4Bytes(num_channels * PLAY_LENGTH * SAMPLE_RATE, 46);
	write4CC('data', 50); //data description header
	write4Bytes(PLAY_LENGTH * SAMPLE_RATE * num_channels * bytes_per_sample, 54); //size of data
	std::cout<<"Done\n";
}
示例#2
0
void test_release_compression_logic(){
CEXCEPTION_T error;
  Stream *inStream = NULL;
  Stream *outStream = NULL;
  State yProgress = {.state = 0, .index = 0};
  State cbProgress = {.state = 0, .index = 0};
  State crProgress = {.state = 0, .index = 0};
  float inputMatrixA[8][8], inputMatrixB[8][8], inputMatrixC[8][8];
  short int outMatrixA[8][8], outMatrixB[8][8], outMatrixC[8][8];
  int size = 8; uint32 bytesToWrite;
  RGB colorRGB; YCbCr lumaChrom;

  uint8 R[8][8], G[8][8], B[8][8];
	uint8 Y[8][8], Cb[8][8], Cr[8][8];
  
  colorRGB.red = &R; colorRGB.green = &G; colorRGB.blue = &B;
  lumaChrom.Y = &Y; lumaChrom.Cb = &Cb; lumaChrom.Cr = &Cr;
	
	Try{
    inStream = openStream("test/Data/Water lilies.7z.010", "rb");
    outStream = openStream("test/Data/outputData.7z.010", "wb");
  }Catch(error){
    TEST_ASSERT_EQUAL(ERR_FILE_NOT_EXIST, error);
  }
  
  readFileToRGB(inStream,R,G,B);
  
  convertToLuma(&colorRGB, &lumaChrom);
  convertToChromaB(&colorRGB, &lumaChrom);
  convertToChromaR(&colorRGB, &lumaChrom);
  
  convertUINT8ToFloat(Y, inputMatrixA);
  convertUINT8ToFloat(Cb, inputMatrixB);
  convertUINT8ToFloat(Cr, inputMatrixC);
  
  normalizeMatrix(8,inputMatrixA);
  normalizeMatrix(8,inputMatrixB);
  normalizeMatrix(8,inputMatrixC);
  
  twoD_DCT(8,inputMatrixA);
  twoD_DCT(8,inputMatrixB);
  twoD_DCT(8,inputMatrixC);
  
  quantizationFunction50(8,inputMatrixA); //Y array
  quantizationFunction50(8,inputMatrixB); //Cb array
  quantizationFunction50(8,inputMatrixC); //Cr array
  
  convertToUINT16(inputMatrixA, outMatrixA);
  convertToUINT16(inputMatrixB, outMatrixB);
  convertToUINT16(inputMatrixC, outMatrixC);
  bytesToWrite = huffmanEncodePull(&yProgress, outMatrixA, dcLuminanceTable);
  write4Bytes(outStream, bytesToWrite);
  
  while(yProgress.index != 64){
    bytesToWrite = huffmanEncodePull(&yProgress, outMatrixA, acLuminanceTable);
    write4Bytes(outStream, bytesToWrite);
  }
  
  bytesToWrite = huffmanEncodePull(&cbProgress, outMatrixB, dcChrominanceTable);
  write4Bytes(outStream, bytesToWrite);
  
  while(cbProgress.index != 64){
    bytesToWrite = huffmanEncodePull(&cbProgress, outMatrixB, acChrominanceTable);
    write4Bytes(outStream, bytesToWrite);
  }
  
  bytesToWrite = huffmanEncodePull(&crProgress, outMatrixC, dcChrominanceTable);
  write4Bytes(outStream, bytesToWrite);
  
  while(crProgress.index != 64){
    bytesToWrite = huffmanEncodePull(&crProgress, outMatrixC, acChrominanceTable);
    write4Bytes(outStream, bytesToWrite);
  }
  
  //To Encoder..... can only detect state.index to stop when it is 64
  //To Byte Stuff, output to file in Y, Cb, Cr
  //Repeat process until (!feof(inStream))
  
  closeStream(inStream);
  closeStream(outStream);
}

// convertToLuma(&colorRGB, &lumaChrom); convertToChromaB(&colorRGB, &lumaChrom); convertToChromaR(&colorRGB, &lumaChrom);
// dumpMatrixUINT8(8,Y); dumpMatrixUINT8(8,Cb); dumpMatrixUINT8(8,Cr);
// dumpMatrixUINT8(8,R); dumpMatrixUINT8(8,G); dumpMatrixUINT8(8,B);

// printf("\n");
// convertToRed(&colorRGB, &lumaChrom); convertToBlue(&colorRGB, &lumaChrom); convertToGreen(&colorRGB, &lumaChrom);
// dumpMatrixUINT8(8,R); dumpMatrixUINT8(8,G); dumpMatrixUINT8(8,B);

// dumpMatrix(8, inputMatrixA);
// dumpMatrix(8, inputMatrixB);
// dumpMatrix(8, inputMatrixC);

void xtest_release_decompression_logic(){
  //Huffman decoder
  //To Run Length Decode
  //Loop 3 times to get Y Cb Cr arrays
  //De-Q - IDCT - Denormalization - Color Conversion back to RGB
  //Output to file again
}
示例#3
0
void test_release_compression_logic(){
CEXCEPTION_T error;
  Stream *inStream = NULL;
  Stream *outStream = NULL;
  State yProgress = {.state = 0, .index = 0};
  State cbProgress = {.state = 0, .index = 0};
  State crProgress = {.state = 0, .index = 0};
  float inputMatrixA[8][8], inputMatrixB[8][8], inputMatrixC[8][8];
  short int outMatrixA[8][8], outMatrixB[8][8], outMatrixC[8][8];
  int size = 8; uint32 bytesToWrite;
  RGB colorRGB; YCbCr lumaChrom;

  uint8 R[8][8], G[8][8], B[8][8];
	uint8 Y[8][8], Cb[8][8], Cr[8][8];
  
  colorRGB.red = &R; colorRGB.green = &G; colorRGB.blue = &B;
  lumaChrom.Y = &Y; lumaChrom.Cb = &Cb; lumaChrom.Cr = &Cr;
	
	Try{
    inStream = openStream("test/Data/Water lilies.7z.010", "rb");
    outStream = openStream("test/Data/outputData.7z.010", "wb");
  }Catch(error){
    TEST_ASSERT_EQUAL(ERR_FILE_NOT_EXIST, error);
  }
  
  readFileToRGB(inStream,R,G,B);
  
  convertToLuma(&colorRGB, &lumaChrom);
  convertToChromaB(&colorRGB, &lumaChrom);
  convertToChromaR(&colorRGB, &lumaChrom);
  
  convertUINT8ToFloat(Y, inputMatrixA);
  convertUINT8ToFloat(Cb, inputMatrixB);
  convertUINT8ToFloat(Cr, inputMatrixC);
  
  normalizeMatrix(8,inputMatrixA);
  normalizeMatrix(8,inputMatrixB);
  normalizeMatrix(8,inputMatrixC);
  
  twoD_DCT(8,inputMatrixA);
  twoD_DCT(8,inputMatrixB);
  twoD_DCT(8,inputMatrixC);
  
  quantizationFunction50(8,inputMatrixA); //Y array
  quantizationFunction50(8,inputMatrixB); //Cb array
  quantizationFunction50(8,inputMatrixC); //Cr array
  
  convertToUINT16(inputMatrixA, outMatrixA);
  convertToUINT16(inputMatrixB, outMatrixB);
  convertToUINT16(inputMatrixC, outMatrixC);
  bytesToWrite = huffmanEncodePull(&yProgress, outMatrixA, dcLuminanceTable);
  write4Bytes(outStream, bytesToWrite);
  
  while(yProgress.index != 64){
    bytesToWrite = huffmanEncodePull(&yProgress, outMatrixA, acLuminanceTable);
    write4Bytes(outStream, bytesToWrite);
  }
  
  bytesToWrite = huffmanEncodePull(&cbProgress, outMatrixB, dcChrominanceTable);
  write4Bytes(outStream, bytesToWrite);
  
  while(cbProgress.index != 64){
    bytesToWrite = huffmanEncodePull(&cbProgress, outMatrixB, acChrominanceTable);
    write4Bytes(outStream, bytesToWrite);
  }
  
  bytesToWrite = huffmanEncodePull(&crProgress, outMatrixC, dcChrominanceTable);
  write4Bytes(outStream, bytesToWrite);
  
  while(crProgress.index != 64){
    bytesToWrite = huffmanEncodePull(&crProgress, outMatrixC, acChrominanceTable);
    write4Bytes(outStream, bytesToWrite);
  }
  
  //To Encoder..... can only detect state.index to stop when it is 64
  //To Byte Stuff, output to file in Y, Cb, Cr
  //Repeat process until (!feof(inStream))
  
  closeStream(inStream);
  closeStream(outStream);
}

// convertToLuma(&colorRGB, &lumaChrom); convertToChromaB(&colorRGB, &lumaChrom); convertToChromaR(&colorRGB, &lumaChrom);
// dumpMatrixUINT8(8,Y); dumpMatrixUINT8(8,Cb); dumpMatrixUINT8(8,Cr);
// dumpMatrixUINT8(8,R); dumpMatrixUINT8(8,G); dumpMatrixUINT8(8,B);

// printf("\n");
// convertToRed(&colorRGB, &lumaChrom); convertToBlue(&colorRGB, &lumaChrom); convertToGreen(&colorRGB, &lumaChrom);
// dumpMatrixUINT8(8,R); dumpMatrixUINT8(8,G); dumpMatrixUINT8(8,B);

// dumpMatrix(8, inputMatrixA);
// dumpMatrix(8, inputMatrixB);
// dumpMatrix(8, inputMatrixC);

void xtest_release_decompression_logic(){
  CEXCEPTION_T error;
  Stream *inStream = NULL;
  Stream *outStream = NULL;
  CodeTable *dcDecodeLumTable = createTable(DCLumTable, 0, sizeof(DCLumTable)/sizeof(RunSizeCode));
  CodeTable *dcDecodeChromTable = createTable(DCChromTable, 0, sizeof(DCChromTable)/sizeof(RunSizeCode));
  CodeTable *acDecodeLumTable = createTable(ACLumTable, 0, sizeof(ACLumTable)/sizeof(RunSizeCode));
  CodeTable *acDecodeChromTable = createTable(ACChromTable, 0, sizeof(ACChromTable)/sizeof(RunSizeCode));
  uint32 bytesToRead, catAndSymbol, runAndDecodedSymbol;
  uint16 codeWord, symbol, runLength, category;
  uint8 runAndSize;
  int16 valueDecodedSymbol;
  int count = 0;
  
  Try{
    inStream = openStream("test/Data/outputData.7z.010", "rb");
    outStream = openStream("test/Data/outputDataDecompress.7z.010", "wb");
  }Catch(error){
    TEST_ASSERT_EQUAL(ERR_FILE_NOT_EXIST, error);
  }
  
  /*bytesToRead = read4Bytes(inStream);
  
  codeWord = bytesToRead >> 16;
  symbol = bytesToRead & 0xffff;
  
  runAndSize = huffmanDecode(codeWord, dcDecodeLumTable);
  runLength = runAndSize >> 4;
  category = runAndSize & 0xf;
  
  catAndSymbol = category;
  catAndSymbol = (catAndSymbol << 16) | symbol;
  
  valueDecodedSymbol = valueDecoding(catAndSymbol);
  
  runAndDecodedSymbol = runLength;
  runAndDecodedSymbol = (runAndDecodedSymbol << 16) | valueDecodedSymbol;
  
  //runAndDecodedSymbol to run-length decode
  while(count < 63){
    bytesToRead = read4Bytes(inStream);
  
    codeWord = bytesToRead >> 16;
    symbol = bytesToRead & 0xffff;
    
    runAndSize = huffmanDecode(codeWord, acDecodeLumTable);
    runLength = runAndSize >> 4;
    category = runAndSize & 0xf;
    
    catAndSymbol = category;
    catAndSymbol = (catAndSymbol << 16) | symbol;
    
    valueDecodedSymbol = valueDecoding(catAndSymbol);
    
    runAndDecodedSymbol = runLength;
    runAndDecodedSymbol = (runAndDecodedSymbol << 16) | valueDecodedSymbol;
    //runAndDecodedSymbol to run-length decode
    
    count++;
  }
  
  bytesToRead = read4Bytes(inStream);
  
  codeWord = bytesToRead >> 16;
  symbol = bytesToRead & 0xffff;
  
  runAndSize = huffmanDecode(codeWord, dcDecodeChromTable);
  runLength = runAndSize >> 4;
  category = runAndSize & 0xf;
  
  catAndSymbol = category;
  catAndSymbol = (catAndSymbol << 16) | symbol;
  
  valueDecodedSymbol = valueDecoding(catAndSymbol);
  
  runAndDecodedSymbol = runLength;
  runAndDecodedSymbol = (runAndDecodedSymbol << 16) | valueDecodedSymbol;
  
  //runAndDecodedSymbol to run-length decode
  while(count < 63){
    bytesToRead = read4Bytes(inStream);
  
    codeWord = bytesToRead >> 16;
    symbol = bytesToRead & 0xffff;
    
    runAndSize = huffmanDecode(codeWord, acDecodeChromTable);
    runLength = runAndSize >> 4;
    category = runAndSize & 0xf;
    
    catAndSymbol = category;
    catAndSymbol = (catAndSymbol << 16) | symbol;
    
    valueDecodedSymbol = valueDecoding(catAndSymbol);
    
    runAndDecodedSymbol = runLength;
    runAndDecodedSymbol = (runAndDecodedSymbol << 16) | valueDecodedSymbol;
    //runAndDecodedSymbol to run-length decode
    
    count++;
  }
  
  bytesToRead = read4Bytes(inStream);
  
  codeWord = bytesToRead >> 16;
  symbol = bytesToRead & 0xffff;
  
  runAndSize = huffmanDecode(codeWord, dcDecodeChromTable);
  runLength = runAndSize >> 4;
  category = runAndSize & 0xf;
  
  catAndSymbol = category;
  catAndSymbol = (catAndSymbol << 16) | symbol;
  
  valueDecodedSymbol = valueDecoding(catAndSymbol);
  
  runAndDecodedSymbol = runLength;
  runAndDecodedSymbol = (runAndDecodedSymbol << 16) | valueDecodedSymbol;
  
  //runAndDecodedSymbol to run-length decode
  while(count < 63){
    bytesToRead = read4Bytes(inStream);
  
    codeWord = bytesToRead >> 16;
    symbol = bytesToRead & 0xffff;
    
    runAndSize = huffmanDecode(codeWord, acDecodeChromTable);
    runLength = runAndSize >> 4;
    category = runAndSize & 0xf;
    
    catAndSymbol = category;
    catAndSymbol = (catAndSymbol << 16) | symbol;
    
    valueDecodedSymbol = valueDecoding(catAndSymbol);
    
    runAndDecodedSymbol = runLength;
    runAndDecodedSymbol = (runAndDecodedSymbol << 16) | valueDecodedSymbol;
    //runAndDecodedSymbol to run-length decode

    
    count++;
  }*/
  
  closeStream(inStream);
  closeStream(outStream);
  //Huffman decoder
  //To Run Length Decode
  //Loop 3 times to get Y Cb Cr arrays
  //De-Q - IDCT - Denormalization - Color Conversion back to RGB
  //Output to file again
}