xtrm0 Posted June 25, 2012 Report Share Posted June 25, 2012 Boas. Alguém sabe de uma forma de abrir um ficheiro wav e desenhar a onda, tipo como aparece no adobe audition? <Signature goes here> Link to comment Share on other sites More sharing options...
pikax Posted June 25, 2012 Report Share Posted June 25, 2012 espero que isto te ajude http://stackoverflow.com/questions/9025111/continuous-waveform-audio-synthesizer Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast." Link to comment Share on other sites More sharing options...
xtrm0 Posted June 25, 2012 Author Report Share Posted June 25, 2012 Acho que o que está nessa página não me ajuda muito. 😞 Eu só quero abrir o saber o waveform e ir sabendo os valores das amplitudes da onda. BTW, estou a utilizar windows. <Signature goes here> Link to comment Share on other sites More sharing options...
seuqram Posted June 25, 2012 Report Share Posted June 25, 2012 (edited) que tal isto? :/ http://www.techmind.org/wave/ http://support.microsoft.com/kb/102585/pt-br espero que te ajude! Edited June 25, 2012 by seuqram Link to comment Share on other sites More sharing options...
xtrm0 Posted June 25, 2012 Author Report Share Posted June 25, 2012 (edited) Não consigo abrir ficheiros com essas bibliotecas. No entanto consegui abrir os ficheiros wav da maneira "tradicional" e extrair as ondas. Só que aparece um desenho um pouco estranho: Como é que posso juntar os pontos com alegro? Código original: #include <allegro5/allegro.h> #include <allegro5/allegro_primitives.h> #include <allegro5/allegro_native_dialog.h> #include <allegro5/allegro_font.h> #include <allegro5/allegro_ttf.h> #include <cstdio> #include <iostream> #pragma comment( lib, "allegro-5.0.6-monolith-md-debug.lib" ) using namespace std; struct xwaveform{ DWORD format_length; short format_tag; short channels; DWORD sample_rate; short avg_bytes_sec; short block_align; short bits_per_sample; BYTE id; DWORD data_size; BYTE * sound_buffer; }; const int width = 800; const int height = 200; const int zoom = 1; //zoom de 100x xwaveform wava; float points[1000000]; //maximos 1000000frames; int main() { al_init(); al_init_primitives_addon(); al_init_font_addon(); al_init_ttf_addon(); ALLEGRO_DISPLAY *display = NULL; display = al_create_display(width, height); //Código para carregar a waveform: FILE *fp; BYTE id[4]; //four bytes to hold 'RIFF' DWORD size; //32 bit value to hold file size fp = fopen("sound.wav","rb"); if (fp) { fread(id,sizeof(BYTE),4,fp); //read in first four bytes cout << id[0] << id[1] << id[2] << id[3] << endl; if (id[0]=='R' && id[1]=='I' && id[2]=='F' && id[3]=='F') { //we had 'RIFF' let's continue fread(&size, sizeof(DWORD), 1, fp); //read in 32bit size value fread(id, sizeof(BYTE), 4, fp); //read in 4 byte string now if (id[0]=='W' && id[1]=='A' && id[2]=='V' && id[3]=='E') { //this is probably a wave file since it contained "WAVE" fread(id, sizeof(BYTE), 4, fp); //read in 4 bytes "fmt "; fread(&wava.format_length, sizeof(DWORD),1,fp); fread(&wava.format_tag, sizeof(short), 1, fp); //check mmreg.h (i think?) for other // possible format tags like ADPCM fread(&wava.channels, sizeof(short),1,fp); //1 mono, 2 stereo fread(&wava.sample_rate, sizeof(DWORD), 1, fp); //like 44100, 22050, etc... fread(&wava.avg_bytes_sec, sizeof(short), 1, fp); //probably won't need this fread(&wava.block_align, sizeof(short), 1, fp); //probably won't need this fread(&wava.bits_per_sample, sizeof(short), 1, fp); //8 bit or 16 bit file? fread(&wava.id, sizeof(BYTE), 4, fp); //read in 'data' fread(&wava.data_size, sizeof(DWORD), 1, fp); //how many bytes of sound data we have wava.sound_buffer = (BYTE *) malloc (sizeof(BYTE) * size); //set aside sound buffer space fread(wava.sound_buffer, sizeof(BYTE), size, fp); //read in our whole sound data chunk cout << "Completo com sucesso!" << endl; } else printf("Error: RIFF file but not a wave file\n"); } else printf("Error: not a RIFF file\n"); } cout << "fim do carregamento" << endl; cout << "id: " << id << endl; cout << "size: " << size << endl; cout << "format_length: " << wava.format_length << endl; cout << "format_tag: " << wava.format_tag << endl; cout << "channels: " << wava.channels << endl; cout << "sample_rate: " << wava.sample_rate << endl; cout << "avg_bytes_sec: " << wava.avg_bytes_sec << endl; cout << "block_align: " << wava.block_align << endl; cout << "bits_per_sample: " << wava.bits_per_sample << endl; cout << "wavaid: " << wava.id << endl; cout << "data_size: " << wava.data_size << endl; cout << "iniciar draw" << endl; al_clear_to_color(al_map_rgb(0,0,0)); for (int i=0; i<size*2; i+=2) { al_draw_pixel(((i/2.0)/((float)size))*width*zoom, (((float)(wava.sound_buffer[(i+1)/2]))/255.0)*height, al_map_rgb(255,255,255)); } al_flip_display(); cout << "draw completo" << endl; al_rest(10.0); al_destroy_display(display); } Edited June 25, 2012 by xtrm0 <Signature goes here> Link to comment Share on other sites More sharing options...
bsccara Posted June 25, 2012 Report Share Posted June 25, 2012 Para carregares o ficheiro para memória: http://www.codeproject.com/Articles/29676/CWave-A-Simple-C-Class-to-Manipulate-WAV-Files. Como é que posso juntar os pontos com alegro? Desenha com segmentos de linha entre pontos. Link to comment Share on other sites More sharing options...
seuqram Posted June 25, 2012 Report Share Posted June 25, 2012 (edited) a imagem não se vê 😕 para unir os pontos podes usar o line(); função line(da biblioteca allegro): line(BITMAP(exemplo:buffer,screen),x inicial,y inicial,x final,y final,makecol(cor vermelha,cor azul,cor verde)); exemplo: line(tela,0,0,800,600,makecol(150,150,150)); traça a diagonal da janela com cor cinzenta assim podes unir os pontos! Edited June 25, 2012 by seuqram Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted June 26, 2012 Report Share Posted June 26, 2012 ui ... vamos ver quem consegue fazer melhor ?? uma corridinha Allegro vs SDL ??? IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
seuqram Posted June 26, 2012 Report Share Posted June 26, 2012 (edited) uma corridinha Allegro vs SDL ??? Eu por acaso nunca estudei SDL por causa da instalação da biblioteca, por isso não posso dizer se é melhor ou não. Só sei, que com allegro, consigo fazer coisas muito boas! vamos ver quem consegue fazer melhor ?? queres fazer algum jogo para ver se é melhor que os meus em allegro? sem usar classes, se não perco xD Edited June 26, 2012 by seuqram Link to comment Share on other sites More sharing options...
pikax Posted June 26, 2012 Report Share Posted June 26, 2012 (edited) queres fazer algum jogo para ver se é melhor que os meus em allegro? sem usar classes, se não perco xD Pode-se usar estruturas? 😛 Edited June 26, 2012 by pikax Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast." Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now