我想使用FFMPEG将我的UUID变成独特的声音,但我不确定如何做到这一点。
所以现在我的UUID看起来像这样:'1e859915-bcdf-4862-8af2-bb43f04e2158'
就像UUID是唯一的一样,我想让它们全部变成独特的1-2秒音频文件。 FFMPEG可以这样做还是有不同的路线?是FFMPEG中的SINE功能还能做什么?
答案 0 :(得分:1)
这是尝试将GUID中的每个半字节变成A4-C6
范围内的音调。
它在WAVE中输出无符号8位PCM,不需要ffmpeg
。该代码仅用于说明目的,随意添加适当的验证等。
#include <stdio.h>
#include <inttypes.h>
#include <math.h>
int main(void) {
FILE* out;
int duration = 2; // [s]
int32_t rate = 44100; // [Hz]
uint8_t guid[] = {0x1e, 0x85, 0x99, 0x15, 0xbc, 0xdf, 0x48, 0x62, 0x8a, 0xf2, 0xbb, 0x43, 0xf0, 0x4e, 0x21, 0x58};
int32_t samples_per_nibble = (float) duration / 32 * rate;
int32_t total_samples = samples_per_nibble * 32;
int16_t c16;
int32_t c32;
if ((out = fopen("test.wav", "wb")) == NULL) {
return 1;
}
// WAV header
// ChunkID
fputs("RIFF", out);
// ChunkSize
c32 = 36 + total_samples;
fwrite(&c32, 4, 1, out);
// Format
fputs("WAVE", out);
// Subchunk1ID
fputs("fmt ", out);
// Subchunk1Size
c32 = 16;
fwrite(&c32, 4, 1, out);
// AudioFormat
c16 = 1;
fwrite(&c16, 2, 1, out);
// NumChannels
c16 = 1;
fwrite(&c16, 2, 1, out);
// SampleRate
c32 = rate;
fwrite(&c32, 4, 1, out);
// ByteRate
c32 = rate;
fwrite(&c32, 4, 1, out);
// BlockAlign
c16 = 1;
fwrite(&c16, 2, 1, out);
// BitsPerSample
c16 = 8;
fwrite(&c16, 2, 1, out);
// Subchunk2ID
fputs("data", out);
// Subchunk2Size
c32 = total_samples;
fwrite(&c32, 4, 1, out);
// Data
for (int b = 0; b < 16; b++) {
// for each byte in the GUID
for (int n = 0; n < 2; n++) {
// for each nibble
uint8_t nibble = (n ? guid[b] >> 4 : guid[b]) & 0x0f;
// go nibble steps above A4
float frequency = 440.0 * pow(1.059463094359, nibble);
// write the samples
for (int s = 0; s < samples_per_nibble; s++) {
int sample = (sin(frequency * 2 * M_PI * s / rate) + 1) * 0.5 * 255;
fputc(sample, out);
}
}
}
fclose(out);
return 0;
}