WAV qismlarini yaratish

Mavjud WAV fayliga maxsus qismlarni qo'shishga harakat qilaman. MmioCreateChunk funktsiyasidan foydalanyapman, lekin bajarilgandan keyin hech narsa o'zgarmaydi. Men dasturning kodi:

#include  
#include  
#include 
#include 

using namespace std;

#pragma comment( lib, "winmm" )

int main() 
{
  HMMIO       hmmio;                //file handle for open file 
  MMCKINFO    mmckinfoParent;       //parent chunk information 
  MMCKINFO    mmckinfoFormatChunk;  //Format chunk information structure 
  MMCKINFO    mmckinfoDataChunk;    //Data chunk information structure
  MMCKINFO    mmckinfoRdibChunk;    //Rdib chunk information structure

 //Open the file for reading with buffered I/O 
 //by using the default internal buffer   
  if(!(hmmio = mmioOpen(L"out.wav", NULL, 
    MMIO_READ))) 
  { 
    cout << "Error opening file." << endl;
    return 0; 
  }

 //Locate a "RIFF" chunk with a "WAVE" form type to make 
 //sure the file is a waveform-audio file. 
  mmckinfoParent.fccType = mmioFOURCC('W', 'A', 'V', 'E'); 
  if (mmioDescend(hmmio, (LPMMCKINFO) &mmckinfoParent, NULL, 
    MMIO_FINDRIFF)) 
  { 
    cout << "This is not a waveform-audio file." << endl; 
    mmioClose(hmmio, 0); 
    return 0; 
  }

 //Find the "FMT" chunk (form type "FMT"); it must be 
 //a subchunk of the "RIFF" chunk. 
  mmckinfoFormatChunk.ckid = mmioFOURCC('f', 'm', 't', ' '); 
  if (mmioDescend(hmmio, &mmckinfoFormatChunk, &mmckinfoParent, 
    MMIO_FINDCHUNK)) 
  { 
    cout << "Waveform-audio file has no \"FMT\" chunk." << endl; 
    mmioClose(hmmio, 0); 
    return 0; 
  }

  unsigned int fmtSize = mmckinfoFormatChunk.cksize;
  char * waveFmt = new char[fmtSize];
  mmioRead(hmmio, waveFmt, mmckinfoFormatChunk.cksize);

  mmioAscend(hmmio, &mmckinfoFormatChunk, 0); 

 //Find the data subchunk. The current file position should be at 
 //the beginning of the data chunk; however, you should not make 
 //this assumption. Use mmioDescend to locate the data chunk. 
  mmckinfoDataChunk.ckid = mmioFOURCC('d', 'a', 't', 'a'); 
  if (mmioDescend(hmmio, &mmckinfoDataChunk, &mmckinfoParent, 
    MMIO_FINDCHUNK)) 
  { 
    cout << "Waveform-audio file has no data chunk." << endl; 
    mmioClose(hmmio, 0); 
    return 0;
  }

  unsigned int size = mmckinfoDataChunk.cksize;
  char* data = new char[size];
  mmioRead(hmmio, data, size);
  mmioClose(hmmio, 0);

  ifstream fs;
  fs.open("out.txt");

 //get length of file:
  fs.seekg (0, ios::end);
  int length = fs.tellg();
  fs.seekg (0, ios::beg);

 //allocate memory:
  char* buffer = new char [length];

 //read data as a block:
  fs.read (buffer,length);
  fs.close();

  HMMIO hmmio_out;

  //Creating new wav file.
  hmmio_out = mmioOpen(L"test.wav", 0, MMIO_CREATE | MMIO_WRITE);

  //Creating RIFF chunk
  mmioCreateChunk(hmmio_out, &mmckinfoParent, MMIO_CREATERIFF);

  //Creating format chunk and inserting information from source file
  mmioCreateChunk(hmmio_out, &mmckinfoFormatChunk, 0);
  mmioWrite(hmmio_out, waveFmt, mmckinfoFormatChunk.cksize);

  mmioAscend(hmmio_out, &mmckinfoFormatChunk, 0);

  //Creating data chunk and inserting information from source file
  mmioCreateChunk(hmmio_out, &mmckinfoDataChunk, 0);
  mmioWrite(hmmio_out, data, mmckinfoDataChunk.cksize);

  mmioAscend(hmmio_out, &mmckinfoDataChunk, 0);

  //Creating new rdib chunk and inserting information from out.txt
  mmckinfoRdibChunk.ckid = mmioFOURCC('r', 'd', 'i', 'b');
  mmckinfoRdibChunk.cksize = sizeof(char) * length;
  mmioCreateChunk(hmmio_out, &mmckinfoRdibChunk, 0);

  mmioWrite(hmmio_out, buffer, sizeof(char) * length);

  mmioAscend(hmmio_out, &mmckinfoRdibChunk, 0);

 //Close the file. 
  mmioClose(hmmio_out, 0); 

  return 0; 
}

Yangi tovoq hosil qilish uchun nima qilishim kerak?

0

3 javoblar

mmioDescend joriy fayl holatida qidirishni boshlaydi. Shunday qilib, yangi yozuvni topa olmaysiz. Avval fayl manzilini dastlabki yoki oldingi blokka tiklashingiz kerak. Boshqa katak joylarni (ckSize va fccType) to'g'ri o'rnatdingizmi? Ehtimol, to'ldirishni to'g'rilash uchun to'plamni yaratganingizdan so'ng mmioAscendni bajarishingiz kerak.

1
qo'shib qo'ydi
Siz uzunligi uzunligini fayl uzunligiga sozlaysizmi? Chiqa to'liq bo'lmasligi mumkin (unda bir nechta bayt bo'lishi kerak) va shuning uchun RIFF ko'rinishi uni ko'rmasligi mumkin.
qo'shib qo'ydi muallif Han, manba
RIFF faylini tuzish uchun RIFF view ilovasidan foydalanmoqdaman va u yangi tovush topa olmaydi. Lekin men faylni notepad ++ da ochsam, unga kiritilgan ma'lumotlarni ko'rsam bo'ladi. Bu mening muammom. O'zgartirilgan mavzudagi asosiy xabarda yangi kodni ko'rishingiz mumkin.
qo'shib qo'ydi muallif Alexander Taraymovich, manba
hmmio_out = mmioOpen(L"test.wav", 0, MMIO_CREATE | MMIO_WRITE);

bo'lishi kerak

hmmio_out = mmioOpen(L"test.wav", 0, MMIO_CREATE | MMIO_READWRITE);

MMIO_CREATE tufayli fayl mazmunini o'chirib tashlashga e'tibor bering;

0
qo'shib qo'ydi

RIFF spesifikatsiyasining ichki qismida ko'ring:

Muvaffaqiyatli bo`lsa, mmioCreateChunk() joriy faylning manzilini o`zgartiradi   yangi qismning ma'lumot maydonining boshlanishi (va keyinchalik,   RIFF yoki LIST chizmalari uchun yozing). Katalogning tarkibi keyinchalik bo'lishi mumkin   mmioWrite() yordamida yoziladigan yoki subchunk boshqa dastur bilan yaratilishi mumkin   mmioCreateChunk() ga qo'ng'iroq qiling. MmioCreateChunk() funktsiyasini qo'shishni unutmang   oldindan mavjud bo'lgan faylga biriktiriladi. Agar bunga urinishgan bo'lsa,   faylda mavjud bo'lgan ma'lumotlar o'chiriladi.

0
qo'shib qo'ydi
Men ham yangi faylni yaratishga va mavjud fayldan ma'lumotni nusxalashga harakat qildim, biroq natija bir xil edi.
qo'shib qo'ydi muallif Alexander Taraymovich, manba
Ushbu faylga yozishni istagan ma'lumotni qo'shadi, biroq u bu faylni taniy olmaydi.
qo'shib qo'ydi muallif Alexander Taraymovich, manba