⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 audriv_none.c

📁 MIDI解码程序(用VC编写)
💻 C
字号:
/*    TiMidity++ -- MIDI to WAVE converter and player    Copyright (C) 1999-2002 Masanao Izumo <mo@goice.co.jp>    Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with this program; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*/#ifdef HAVE_CONFIG_H#include "config.h"#endif /* HAVE_CONFIG_H */#include <stdio.h>#ifndef NO_STRING_H#include <string.h>#else#include <strings.h>#endif#include "timidity.h"#include "aenc.h"#include "audriv.h"#include "timer.h"#ifdef DEBUG#include "audio_cnv.h"#include <math.h>#endifvoid (* audriv_error_handler)(const char *errmsg) = NULL;static int play_sample_rate = 8000;static int play_sample_size = 1;static double play_start_time;static long play_counter, reset_samples;static int play_encoding   = AENC_G711_ULAW;static int play_channels = 1;static int output_port = AUDRIV_OUTPUT_SPEAKER;static int play_volume   = 0;static Bool play_open_flag = False;char audriv_errmsg[BUFSIZ];static void audriv_err(const char *msg){    strncpy(audriv_errmsg, msg, sizeof(audriv_errmsg) - 1);    if(audriv_error_handler != NULL)	audriv_error_handler(audriv_errmsg);}Bool audriv_setup_audio(void)/* オ〖ディオの介袋步を乖いますˉ * 喇根した眷圭は True を·己窃した眷圭は False を手しますˉ */{    return True;}void audriv_free_audio(void)/* audio の稿借妄を乖いますˉ */{}Bool audriv_play_open(void)/* audio を遍琳脱に倡き·いつでも audriv_write() により遍琳材墙な * 觉轮にしますˉ贷に倡いている眷圭はなにも乖いませんˉ * 喇根した眷圭は True を·己窃した眷圭は False を手しますˉ */{    if(play_open_flag)	return True;    play_counter = 0;    reset_samples = 0;    play_open_flag = True;    return True;}void audriv_play_close(void)/* 遍琳脱にオ〖プンされた audio を誓じますˉすでに誓じている * 眷圭はなにも乖いませんˉ */{    play_open_flag = False;}static long calculate_play_samples(void){    long n, ret;    if(play_counter <= 0)	return 0;    n = (long)((double)play_sample_rate	       * (double)play_sample_size	       * (get_current_calender_time() - play_start_time));    if(n > play_counter)	ret = play_counter / play_sample_size;    else	ret = n / play_sample_size;    return ret;}long audriv_play_stop(void)/* 遍琳を篓郝に匿贿し·匿贿木涟のサンプル眶を手しますˉ * audriv_play_stop() の钙び叫しによって·audio は誓じますˉ * audio が贷に誓じている眷圭に audriv_play_stop() を钙び叫した眷圭は 0 を * 手しますˉ * エラ〖の眷圭は -1 を手しますˉ */{    long n;    n = audriv_play_samples();    play_open_flag = False;    return n;}Bool audriv_is_play_open(void)/* audio が遍琳でオ〖プンされている眷圭は True, * 誓じている眷圭は False を手しますˉ */{    return play_open_flag;}Bool audriv_set_play_volume(int volume)/* 遍琳不翁を 0 × 255 の认跋柒で肋年しますˉ0 は痰不·255 は呵络不翁ˉ * 0 踏塔は 0·255 を亩える猛は 255 に霹擦ˉ * 喇根した眷圭は True を·己窃した眷圭は False を手しますˉ */{    if(volume < 0)	play_volume = 0;    else if(volume > 255)	play_volume = 255;    else	play_volume = volume;    return True;}int audriv_get_play_volume(void)/* 遍琳不翁を 0 × 255 柒で评ますˉ0 は痰不·255 は呵络不翁ˉ * 己窃すると -1 を手し·そうでない眷圭は 0 × 255 柒の不翁を手しますˉ */{    return play_volume;}Bool audriv_set_play_output(int port)/* audio の叫蜗黎 port を回年しますˉport には笆布のどれかを回年しますˉ * *     AUDRIV_OUTPUT_SPEAKER	スピ〖カに叫蜗ˉ *     AUDRIV_OUTPUT_HEADPHONE	ヘッドホンに叫蜗ˉ *     AUDRIV_OUTPUT_LINE_OUT	ラインアウトに叫蜗ˉ * * 喇根した眷圭は True を·己窃した眷圭は False を手しますˉ */{    switch(port)    {      case AUDRIV_OUTPUT_SPEAKER:      case AUDRIV_OUTPUT_HEADPHONE:      case AUDRIV_OUTPUT_LINE_OUT:	output_port = port;	break;      default:	audriv_err("回年嘲の叫蜗ポ〖トが回年されましたˉ");	return False;    }    return True;}int audriv_get_play_output(void)/* audio の叫蜗黎 port を评ますˉ * 己窃すると -1 を手し·喇根すると笆布のいずれかの猛を手しますˉ * *     AUDRIV_OUTPUT_SPEAKER	スピ〖カに叫蜗ˉ *     AUDRIV_OUTPUT_HEADPHONE	ヘッドホンに叫蜗ˉ *     AUDRIV_OUTPUT_LINE_OUT	ラインアウトに叫蜗ˉ * */{    return output_port;}#ifdef CFG_FOR_SFstatic int record_volume = 0;#endifint audriv_get_record_volume(void)/* 峡不不翁を 0 × 255 柒で评ますˉ0 は痰不·255 は呵络不翁ˉ * 己窃すると -1 を手し·そうでない眷圭は 0 × 255 柒の不翁を手しますˉ */{    return record_volume;}int audriv_write(char *buff, int n)/* audio に buff を n バイト尸萎し哈みますˉ * audriv_set_noblock_write() で润ブロックˇモ〖ドが肋年された * 眷圭は·この簇眶の钙び叫しは篓郝に借妄が手りますˉ * 手り猛は悸狠に萎し哈まれたバイト眶であり·润ブロックˇモ〖ドが肋年 * されている眷圭は·苞眶 n より警ない眷圭がありますˉ * 己窃すると -1 を手し·喇根すると·悸狠に萎し哈まれたバイト眶を手しますˉ */{    long qsz;    qsz = audriv_get_filled();    if(qsz == -1)	return -1;    if(qsz == 0)    {	reset_samples += play_counter / play_sample_size;	play_counter = 0; /* Reset start time */    }    if(play_counter == 0)	play_start_time = get_current_calender_time();    play_counter += n;    return n;}Bool audriv_set_noblock_write(Bool noblock)/* noblock に True を回年すると·audriv_write() 钙び叫しでブロックしませんˉ * False を回年すると·デフォルトの觉轮に提しますˉ * 借妄に喇根すると True を·己窃すると False を手しますˉ */{    return True;}int audriv_play_active(void)/* 遍琳面なら 1·遍琳面でないなら 0, エラ〖なら -1 を手しますˉ */{    long n;    n = audriv_get_filled();    if(n > 0)	return 1;    return n;}long audriv_play_samples(void)/* 附哼遍琳面のサンプル疤弥を手しますˉ */{    return reset_samples + calculate_play_samples();}long audriv_get_filled(void)/* オ〖ディオバッファ柒のバイト眶を手します。 * エラ〖の眷圭は -1 を手します。 */{    long n;    if(play_counter <= 0)	return 0;    n = (int)((double)play_sample_rate	      * play_sample_size	      * (get_current_calender_time() - play_start_time));    if(n > play_counter)	return 0;    return play_counter - n;}const long *audriv_available_encodings(int *n_ret)/* マシンがサポ〖トしているすべての射规步リストを手しますˉn_ret には * その硷梧の眶が·手されますˉ射规步をあらわす年眶猛は * usffd.h 柒に年盗されている enum usffd_data_encoding の猛ですˉ * 手り猛は free してはなりませんˉ */{    static const long encoding_list[] =    {	AENC_SIGBYTE, AENC_UNSIGBYTE, AENC_G711_ULAW,	AENC_G711_ALAW, AENC_SIGWORDB, AENC_UNSIGWORDB,	AENC_SIGWORDL, AENC_UNSIGWORDL    };    *n_ret = 8;    return encoding_list;}const long *audriv_available_sample_rates(int *n_ret)/* マシンがサポ〖トしているすべてのサンプルレ〖トのリストを手しますˉ * n_ret にはその硷梧の眶が·手されますˉ * 手り猛は free してはなりませんˉ */{    static const long sample_rates[] =    {	5512, 6615,	8000, 9600, 11025, 16000, 18900, 22050, 32000, 37800, 44100, 48000    };    *n_ret = 12;    return sample_rates;}const long *audriv_available_channels(int *n_ret)/* マシンがサポ〖トしているすべてのチャネル眶のリストを手しますˉ * n_ret にはその硷梧の眶が·手されますˉ * 手り猛は free してはなりませんˉ */{    static const long channels[] = {1, 2};    *n_ret = 2;    return channels;}Bool audriv_set_play_encoding(long encoding)/* audio 遍琳箕の射规步数及を回年しますˉ * 喇根した眷圭は True を·己窃した眷圭は False を手しますˉ */{    int i, n;    const long *enc;    enc = audriv_available_encodings(&n);    for(i = 0; i < n; i++)	if(enc[i] == encoding)	{	    play_encoding = encoding;	    play_sample_size = AENC_SAMPW(encoding) * play_channels;	    return True;	}    return False;}Bool audriv_set_play_sample_rate(long sample_rate)/* audio 遍琳箕のサンプルレ〖トを回年しますˉ * 喇根した眷圭は True を·己窃した眷圭は False を手しますˉ */{    int i, n;    const long *r;    r = audriv_available_sample_rates(&n);    for(i = 0; i < n; i++)	if(r[i] == sample_rate)	{	    play_sample_rate = sample_rate;	    return True;	}    return False;}Bool audriv_set_play_channels(long channels)/* 遍琳脱のチャネル眶を肋年しますˉ * 己窃すると False を手し·喇根すると True を手しますˉ */{    int i, n;    const long *c = audriv_available_channels(&n);    for(i = 0; i < n; i++)	if(channels == c[i])	{	    play_channels = channels;	    return True;	}    return False;}void audriv_wait_play(void)/* CPU パワ〖を喜锐しないようにするために·办箕弄に匿贿しますˉ*/{}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -