Linux下调用alsa-lib播放音频(简化版)

直接贴代码:

#include <stdio.h>
#include <stdlib.h>
#include "playWav.h"
#include <alsa/asoundlib.h>

#include <iostream>
using namespace std;

void playSound(const char* filepath)
{
	;
    int i;
    int ret;
    int buf[128];
    unsigned int val;
    int dir=0;
    char *buffer;
    int size;
    snd_pcm_uframes_t frames;
    snd_pcm_uframes_t periodsize;
    snd_pcm_t *playback_handle;//PCM设备句柄pcm.h
    snd_pcm_hw_params_t *hw_params;//硬件信息和PCM流配置

/*    if (argc != 2) {
        printf("error: alsa_play_test [music name]\n");
        exit(1);
    }*/

    cout << "start playing... wav from: /" << filepath << endl;
    FILE *fp = fopen(filepath, "rb");
    if(fp == NULL)
    	return 0;
    fseek(fp, 100, SEEK_SET);

    //1. 打开PCM,最后一个参数为0意味着标准配置
    ret = snd_pcm_open(&playback_handle, "default", SND_PCM_STREAM_PLAYBACK, 0);
    if (re
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值