Chào mừng đến với Diễn đàn lập trình - Cộng đồng lập trình.
Kết quả 1 đến 2 của 2
  1. #1
    Ngày tham gia
    Sep 2015
    Bài viết
    0

    Lỗi khi dùng thư viện libao phát nhạc

    #include <stdlib.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <ao/ao.h>
    #include <vector>
    #include <cmath>
    #include <iostream>
    #include <string.h>
    #include <malloc.h>
    #include <math.h>
    #include "sndfile.h"
    #pragma comment(lib,"libsndfile-1.lib")

    #define PI 3.14;

    using namespace std;
    Mã:
    void playfile( ) {
    	 // Mo File
    	printf("
    Nhap ten file: ");
    	char fileread[120]="";
    	scanf("%s",fileread);
    	SF_INFO sndInfo;
    	SNDFILE *sndFile = sf_open(fileread, SFM_READ, &sndInfo);
    	if (sndFile == NULL) {
    		fprintf(stderr, "Loi mo file '%s': %s
    ", fileread, sf_strerror(sndFile));
    	//	return 1;
    	}
    #define BUF_SIZE 4096
    
    	ao_device *device;
    	ao_sample_format format;
    	int default_driver;
    	int *buffer;
    	int buf_size;
    	int sample;
    	//float freq = 440.0;
    	int i;
    
    	/* -- Initialize -- */
    
    
    
    	ao_initialize();
    
    	/* -- Setup for default driver -- */
    
    	default_driver = ao_default_driver_id();
    
            memset(&format, 0, sizeof(format));
    /*	format.bits = 16;
    	format.channels = 2;
    	format.rate = 44100;
    	format.byte_format = AO_FMT_LITTLE;*/
    
    	/* -- Open driver -- */
    	device = ao_open_live(default_driver, &format, NULL /* no options */);
    	if (device == NULL) {
    		fprintf(stderr, "Error opening device.
    ");
    	
    	}
    
    	/* -- Play some stuff -- */
    	buf_size = sndInfo.format/8 * sndInfo.channels * sndInfo.samplerate;
    	buffer = calloc(buf_size,sizeof(char));
    	for (i = 0; i < sndInfo.format; i++) {
    	//sample = (int)(0.75 * 32768.0 *
    			//sin(2 * M_PI * freq * ((float) i/format.rate)));
    
    		/* Put the same stuff in left and right channel */
    		//buffer[4*i] = buffer[4*i+2] = sample & 0xff;
    	//	buffer[4*i+1] = buffer[4*i+3] = (sample >> 8) & 0xff;
    	}
    	ao_play(device, buffer, buf_size);
    
    	/* -- Close and shutdown -- */
    	ao_close(device);
    
    	ao_shutdown();
    
     //return 1;
    }
    em code xong chạy nó báo lỗi. thay đủ kiểu dạng từu int tới float rồi àm vẫn bị. bác nào sửa dùm em cái [IMG]images/smilies/21.gif[/IMG] [IMG]images/smilies/17.gif[/IMG]
    Error 14 error C2664: 'ao_play' : cannot convert parameter 2 from 'int *' to 'char *'

  2. #2
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    cái tham số thứ 2 - buffer phải là kiểu char*.
    1 là ép kiểu nó sang char* 2 là xem lại xem kiểu của mình dùng đúng chưa.

 

 

Quyền viết bài

  • Bạn Không thể gửi Chủ đề mới
  • Bạn Không thể Gửi trả lời
  • Bạn Không thể Gửi file đính kèm
  • Bạn Không thể Sửa bài viết của mình
  •