- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试“录制”一个音频文件,我读过这个 doc ,实际上我想在文件中将“采样”值记录为双倍值,这是我使用的代码(不起作用,我不知道为什么没有):
/* Use the newer ALSA API */
#define ALSA_PCM_NEW_HW_PARAMS_API
#include <alsa/asoundlib.h>
#include <stdio.h>
int main() {
long loops;
int rc;
int size,z = 0 ;
unsigned int val;
double* buffer;
int dir;
snd_pcm_t *handle;
snd_pcm_hw_params_t *params;
snd_pcm_uframes_t frames;
FILE* output = NULL;
output =fopen("recod_values.txt","w");
/* Open PCM device for recording (capture). */
rc = snd_pcm_open(&handle, "default",
SND_PCM_STREAM_CAPTURE, 0);
if (rc < 0) {
fprintf(stderr,
"unable to open pcm device: %s\n",
snd_strerror(rc));
exit(1);
}
/* Allocate a hardware parameters object. */
snd_pcm_hw_params_alloca(¶ms);
/* Fill it in with default values. */
snd_pcm_hw_params_any(handle, params);
/* Set the desired hardware parameters. */
/* Interleaved mode */
snd_pcm_hw_params_set_access(handle, params,
SND_PCM_ACCESS_RW_INTERLEAVED);
/* Signed 16-bit little-endian format */
snd_pcm_hw_params_set_format(handle, params,
SND_PCM_FORMAT_S16_LE);
/* MONO ! channel */
snd_pcm_hw_params_set_channels(handle, params,1);
/* 96000 bits/second sampling rate */
val = 96000;
snd_pcm_hw_params_set_rate_near(handle, params,
&val, &dir);
;
/* Set period size to 32 frames. */
frames = 32;
snd_pcm_hw_params_set_period_size_near(handle,
params, &frames, &dir);
/* Write the parameters to the driver */
rc = snd_pcm_hw_params(handle, params);
if (rc < 0) {
fprintf(stderr,
"unable to set hw parameters: %s\n",
snd_strerror(rc));
exit(1);
}
/* Use a buffer large enough to hold one period */
snd_pcm_hw_params_get_period_size(params,
&frames, &dir);
size = frames * 1; /* 2 bytes/sample, 2 channels */
buffer = (double*) malloc(size);
/* We want to loop for 5 seconds */
snd_pcm_hw_params_get_period_time(params,
&val, &dir);
loops = 5000000/ val;
while (loops > 0) {
loops--;
rc = snd_pcm_readi(handle, buffer, frames);
for ( z = 0 ; z < size;z++){
fprintf(output,"%lf \n",buffer[z]);
}
}
snd_pcm_drain(handle);
snd_pcm_close(handle);
free(buffer);
fclose(output);
return 0;
}
得到的结果是假的,这是我得到的一部分:
22164315735966424535139159791393084768500567327664428456919459225160782460290374318673978007739264159481013271070331047993933279328468540357215794465042587451392.000000
6279123284769190191779385445935961906015983426866033011058871857355906568111563202057623448515972440403603734829703874073506103294822799230919004382628287132004967906916958208.000000
0.000000
0.000000
0.000000
1144284986495925317233642104161717490326555645567187694497268067386154959544116448945812917900397813140052794333237528352248562790473524666519326385472977850060639877322124157668710305854399264313107197566174852391468506111174989083416952045568.000000
486016490646530877454846463864566567777058339173509861936688900655372986604461971881776121791820561656186713737600239967251495507590158168644511518013315486066797390056338302864276615681456563025411108154944185463301467774199971222422456597209993418331127808.000000
97502070478605056015384266450931746345849383201940068533539715554348065640767209105810488184602958812662140616258325471782047626172052091225732327584237457213932719329242675004694018348986553910427648.000000
0.000000
0.000000
0.000000
0.000000
0.000000
知道如何使它看起来更好吗?提前致谢 !
更新使用Audacity导入输出文件后,结果或声音与录制的声音完全无关!是我做错了吗?我的意思是这部分代码:
loops = 5000000/ val;
while (loops > 0) {
loops--;
rc = snd_pcm_readi(handle, buffer, frames);
for ( z = 0 ; z < size;z++){
fprintf(output,"%lf \n",buffer[z]);
}
}
最佳答案
snd_pcm_readi
以您使用 snd_pcm_hw_params_set_format
设置的格式写入示例,因此您必须确保 buffer
的类型匹配这。double
的等效项是 SND_PCM_FORMAT_FLOAT64
。
此外,malloc
需要一个以 bytes 为单位的大小,因此您必须使用
size = frames * sizeof(double);
打印样本时,您的字节数多于样本数,因此 size
是错误的计数器。返回的样本数在rc
中:
for (z = 0; z < rc; z++)
fprintf(output, "%lf\n", buffer[z]);
关于c - 用 ALSA 录音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24856244/
我正在使用 twilio JS 客户端从 Web 进行调用。客户端调用后端获取 token 。这里是返回 token 的后端代码。如何记录通话。表示在哪里设置录制网址。通话成功。但是不知道从哪里传录音
我有一个软件,可以记录 5 秒间隔的声音,然后将其发送进行处理。它在无限循环中运行,如下所示: while (true) { System.out.println("recording..")
我目前正在做一个项目,需要录制 iPhone 播放的声音。通过这个,我的意思是录制在后台播放的声音,如声音剪辑或其他任何东西,而不是使用内置麦克风。 这能做到吗?我目前正在试验 AVAudioReco
当我将蓝牙免提连接到 Android 手机设备时,是否可以使用手机麦克风录制声音并在免提中听到? 我设法通过手机麦克风录制声音,并通过手机扬声器或耳机听到声音。但是当耳机有麦克风时,通常是免提,它默认
我想访问我在我的应用程序中记录的跟踪数据和自定义数据。 有人可以提供不同数据轨道保存在 mp4 中的格式吗? 使用这个例子https://github.com/google-ar/arcore-and
我想知道,在C++中进行音频记录/回放/搜索的跨平台实用工具是什么?我当时在考虑采用ALUT(OpenAL)的路线,但是有更好的方法吗?如果不是,你们是否知道ALUT的任何优秀教程/示例代码? 最佳答
我目前正在开发一个项目,该项目允许用户录制音频消息,但是最近提出了一个要求,允许他们暂停录制过程,然后继续录制(将新的音频追加到之前的录制之后)。 示例: 用户按下记录并进行初始记录。 用户按下暂停按
我见过几个这样的例子,但它们似乎是针对旧版本的 SDK。我正在尝试设置基本的录音,以下代码在针对 SDK 2.0 版时给我一个 NullPointerException。 ContentValues
我开发了一款安卓游戏,使用 Audio Record 获取麦克风输入。 可以看一下https://play.google.com/store/apps/details?id=fixappmedia.m
我想在最近的项目中使用该插件进行音频捕获。我找到了 Matt Diamond 的努力 demo here正如大多数文章所指向的那样。我尝试在本地重新创建这个完全相同的演示,但没有成功。 我包括了所有依
我正在设置录音机,但在 soundRecorder = try AVAudioRecorder(URL: getFileURL(), settings: recordSettings as! [Str
作为一名吉他手,我一直想开发自己的录音、混音软件。我在 Direct Sound、Windows Multimedia(waveOutOpen 等)方面有一些经验。我意识到这将是一个复杂的项目,但纯粹
我不想记录我自己的击键来创建 asciinema 教程,而是想编写它们的脚本,这样我就可以随着时间的推移轻松地改进我的教程,而不必担心每次我想进行更改时都要重做,或者花很多时间尝试更正录音中的错别字。
我正在尝试使用 Flutter 构建一个应用程序,其中包含录音机。如何访问录音机?请帮我弄清楚它的包、依赖项和代码。 最佳答案 您可以使用 audio_recorder 包: https://pub.
掌握 Java Flight recorder (JFR) 配置,我有一个最合理的配置: -XX:+UnlockCommercialFeatures -XX:+DebugNonSafepoints -
我正在尝试播放我从 twilio 取回的通话录音。到目前为止,我在我的网站上有一个所有通话录音的列表,当我点击它们时,它会将我发送到 twilio 以收听它们。然后我发出一个 ajax 请求以从 tw
我们可以用 iPhone 直接线路输入录制音频吗? 最佳答案 唯一的方法是使用底座连接器创建您自己的配件,然后使用提供的 API! 关于iPhone LINE-IN 录音 可以吗?,我们在Stack
基本上,我希望用户使用 SoundCloud 录音机录制声音,一旦他们单击“保存”,他们刚刚录制的声音就会嵌入到我的网页中。 我使用 SC.record() 方法来获取录音。这是我保存录音的功能...
我正在尝试在网站中实现录音。基本上,用户应该能够按下一个按钮并对着麦克风说些什么。然后应将录制的音频发送到服务器以进行进一步处理。我知道您可以使用 Flash 做到这一点,但现在我正在努力避免这种情况
我正在尝试“录制”一个音频文件,我读过这个 doc ,实际上我想在文件中将“采样”值记录为双倍值,这是我使用的代码(不起作用,我不知道为什么没有): /* Use the newer ALSA API
我是一名优秀的程序员,十分优秀!