本文整理汇总了C++中sf_writef_short函数的典型用法代码示例。如果您正苦于以下问题:C++ sf_writef_short函数的具体用法?C++ sf_writef_short怎么用?C++ sf_writef_short使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sf_writef_short函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
r2_mf_tx_state_t gen;
int16_t amp[1000];
int len;
SNDFILE *outhandle;
int digit;
const char *digits = "0123456789BCDEF";
if ((outhandle = sf_open_telephony_write(OUTPUT_FILE_NAME, 1)) == NULL)
{
fprintf(stderr, " Cannot open audio file '%s'\n", OUTPUT_FILE_NAME);
exit(2);
}
r2_mf_tx_init(&gen, FALSE);
for (digit = 0; digits[digit]; digit++)
{
r2_mf_tx_put(&gen, digits[digit]);
len = r2_mf_tx(&gen, amp, 1000);
printf("Generated %d samples of %c\n", len, digits[digit]);
if (len > 0)
sf_writef_short(outhandle, amp, len);
r2_mf_tx_put(&gen, 0);
len = r2_mf_tx(&gen, amp, 1000);
printf("Generated %d samples\n", len);
if (len > 0)
sf_writef_short(outhandle, amp, len);
}
r2_mf_tx_init(&gen, TRUE);
for (digit = 0; digits[digit]; digit++)
{
r2_mf_tx_put(&gen, digits[digit]);
len = r2_mf_tx(&gen, amp, 1000);
printf("Generated %d samples of %c\n", len, digits[digit]);
if (len > 0)
sf_writef_short(outhandle, amp, len);
r2_mf_tx_put(&gen, 0);
len = r2_mf_tx(&gen, amp, 1000);
printf("Generated %d samples\n", len);
if (len > 0)
sf_writef_short(outhandle, amp, len);
}
if (sf_close_telephony(outhandle))
{
fprintf(stderr, " Cannot close audio file '%s'\n", OUTPUT_FILE_NAME);
exit (2);
}
return 0;
}
示例2: sample_save
int sample_save(channel * channel, const char *filename)
{
#ifdef HAVE_LIBSNDFILE
sf_count_t frameCount;
SNDFILE *outputFile;
SF_INFO sfinfo;
float framesize;
/*
Hardcoded ;)
*/
sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16;
sfinfo.channels = 2;
sfinfo.samplerate = 44100;
outputFile = sf_open(filename, SFM_WRITE, &sfinfo);
if (outputFile == NULL)
return 0;
framesize = sizeof(short) * sfinfo.channels;
frameCount =
channel->parms.d.audio_sample_data.s_length * 2 / framesize;
sf_writef_short(outputFile, channel->data, frameCount);
sf_close(outputFile);
return 0;
#endif
}
示例3: RUNTIME_ERROR
void AudioFileSndfile::write(const void* buffer, unsigned frames)
{
if (!_handle || (_mode != ModeWrite && _mode != ModeReadWrite)) {
RUNTIME_ERROR("Attempt to write file not opened for writing.");
}
flushChunks();
sf_count_t count;
switch (_info.sampleType) {
case Sound::Type::Float32:
case Sound::Type::Int24E:
count = sf_writef_float(_handle.get(), static_cast<const Sound::Float32*>(buffer), frames);
break;
case Sound::Type::Float64:
count = sf_writef_double(_handle.get(), static_cast<const Sound::Float64*>(buffer), frames);
break;
case Sound::Type::Int8:
count = sf_write_raw(_handle.get(), buffer, frames * _info.channels);
break;
case Sound::Type::Int16:
count = sf_writef_short(_handle.get(), static_cast<const Sound::Int16*>(buffer), frames);
break;
case Sound::Type::Int32:
count = sf_writef_int(_handle.get(), static_cast<const Sound::Int32*>(buffer), frames);
break;
case Sound::Type::Int64:
case Sound::Type::Precise:
case Sound::Type::Count:
RUNTIME_ERROR("Writing for this sample format is not supported");
}
}
示例4: main_loop_reverse
void main_loop_reverse(void) {
LTCFrame f;
const long long int end = ceil(duration * samplerate / 1000.0);
long long int written = 0;
active=1;
short *snd = NULL;
const short smult = rint(pow(10, volume_dbfs/20.0) * 32767.0);
while(active==1 && (duration <= 0 || end >= written)) {
int byteCnt;
for (byteCnt = 9; byteCnt >= 0; byteCnt--) {
int i;
ltc_encoder_encode_byte(encoder, byteCnt, -1.0);
const int len = ltc_encoder_get_buffer(encoder, enc_buf);
if (!snd) snd = malloc(len * sizeof(short));
for (i=0;i<len;i++) {
const short val = ( (int)(enc_buf[i] - 128) * smult / 90 );
snd[i] = val;
}
sf_writef_short(sf, snd, len);
written += len;
if (end < written) break;
} /* end byteCnt - one video frames's worth of LTC */
ltc_encoder_get_frame(encoder, &f);
ltc_frame_decrement(&f, ceil(fps_num/fps_den),
fps_num/(double)fps_den == 25.0? LTC_TV_625_50 : LTC_TV_525_60,
LTC_USE_DATE);
ltc_encoder_set_frame(encoder, &f);
}
free(snd);
printf("wrote %lld audio-samples\n", written);
}
示例5: main_loop
void main_loop(void) {
const long long int end = ceil(duration * samplerate / 1000.0);
long long int written = 0;
active=1;
short *snd = NULL;
const short smult = rint(pow(10, volume_dbfs/20.0) * 32767.0);
while(active==1 && (duration <= 0 || end >= written)) {
int byteCnt;
for (byteCnt = 0; byteCnt < 10; byteCnt++) {
int i;
ltc_encoder_encode_byte(encoder, byteCnt, 1.0);
const int len = ltc_encoder_get_buffer(encoder, enc_buf);
if (!snd) snd = malloc(len * sizeof(short));
for (i=0;i<len;i++) {
const short val = ( (int)(enc_buf[i] - 128) * smult / 90 );
snd[i] = val;
}
sf_writef_short(sf, snd, len);
written += len;
if (end < written) break;
} /* end byteCnt - one video frames's worth of LTC */
ltc_encoder_inc_timecode(encoder);
}
free(snd);
printf("wrote %lld audio-samples\n", written);
}
示例6: write_file_at_end
static void
write_file_at_end (int fd, int filetype, int channels, int file_num)
{ SNDFILE *sndfile ;
SF_INFO sfinfo ;
int frames, k ;
lseek (fd, 0, SEEK_END) ;
for (k = 0 ; k < DATA_LENGTH ; k++)
data [k] = k ;
frames = DATA_LENGTH / channels ;
sfinfo.format = filetype ;
sfinfo.channels = channels ;
sfinfo.samplerate = 44100 ;
if ((sndfile = sf_open_fd (fd, SFM_WRITE, &sfinfo, SF_FALSE)) == NULL)
{ printf ("\n\nLine %d: sf_open_fd failed\n", __LINE__) ;
printf ("Embedded file number : %d\n", file_num) ;
puts (sf_strerror (sndfile)) ;
dump_log_buffer (sndfile) ;
exit (1) ;
} ;
if (sf_writef_short (sndfile, data, frames) != frames)
{ printf ("\n\nLine %d: short write\n", __LINE__) ;
printf ("Embedded file number : %d\n", file_num) ;
exit (1) ;
} ;
sf_close (sndfile) ;
} /* write_file_at_end */
示例7: main
int main()
{
SF_INFO wav_info;
SNDFILE *wav;
ayemu_player_t player;
ayemu_player_sndfmt_t format;
short buf[BUFFER_SIZE * 2];
size_t filled_size;
format.freq = wav_info.samplerate = AUDIO_FREQ;
format.channels = wav_info.channels = AUDIO_CHANS;
format.bpc = AUDIO_BITS;
wav_info.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16;
ayemu_player_open_psg( "dancing_queen.psg", &format, &player );
wav = sf_open( "test.wav", SFM_WRITE, &wav_info );
while ( (filled_size = ayemu_player_fill_buffer( &player, buf, BUFFER_SIZE ) ) > 0) {
sf_writef_short( wav, buf, filled_size );
}
sf_close( wav );
ayemu_player_close( &player );
return 0;
}
示例8: sf_writef_short
void DWavVault::AddLogValue(const double value){
//wavfile
int16_t valueI = (int16_t)value;
sf_writef_short( wav, (const short *)&valueI, 1);
m_nrOfRows++;
}
示例9: power_surge_detector_file_test
static int power_surge_detector_file_test(const char *file)
{
SNDFILE *inhandle;
SNDFILE *outhandle;
int inframes;
power_surge_detector_state_t *sig;
int i;
int16_t amp[8000];
int16_t amp_out[2*8000];
int sample;
float signal_power;
int32_t signal_level;
int signal_present;
int prev_signal_present;
if ((inhandle = sf_open_telephony_read(file, 1)) == NULL)
{
printf(" Cannot open speech file '%s'\n", file);
exit(2);
}
if ((outhandle = sf_open_telephony_write(OUT_FILE_NAME, 1)) == NULL)
{
fprintf(stderr, " Cannot create audio file '%s'\n", OUT_FILE_NAME);
exit(2);
}
sig = power_surge_detector_init(NULL, -50.0f, 6.0f);
prev_signal_present = FALSE;
sample = 0;
while ((inframes = sf_readf_short(inhandle, amp, 8000)))
{
for (i = 0; i < inframes; i++)
{
signal_level = power_surge_detector(sig, amp[i]);
signal_present = (signal_level != 0);
if (prev_signal_present != signal_present)
{
signal_power = power_surge_detector_current_dbm0(sig);
if (signal_present)
printf("On at %f (%fdBm0)\n", (sample + i)/8000.0, signal_power);
else
printf("Off at %f (%fdBm0)\n", (sample + i)/8000.0, signal_power);
prev_signal_present = signal_present;
}
amp_out[2*i] = amp[i];
amp_out[2*i + 1] = signal_present*5000;
}
sf_writef_short(outhandle, amp_out, inframes);
sample += inframes;
}
sf_close(inhandle);
sf_close(outhandle);
return 0;
}
示例10: return
ssize_t LibsndfileSink::write(const void *buffer, size_t count)
{
if (!mNegotiated) {
return (ssize_t) NEGOTIATE;
}
if (mSndfile == NULL) {
return (ssize_t) NO_INIT;
}
sf_count_t actual = sf_writef_short(mSndfile, (short *) buffer, (sf_count_t) count);
mFramesWritten += actual;
return actual;
}
示例11: main
int main(void){
Lowpass filters[2];
int i;
SNDFILE *infile = NULL;
SNDFILE *outfile = NULL;
SF_INFO sfinfo;
sf_count_t readcount;
int filetype = SF_FORMAT_WAV | SF_FORMAT_PCM_16;
short buffer[BLOCK_SIZE * 2];
// Open a wav file to filter
if((infile = sf_open ("music.wav", SFM_READ, &sfinfo)) == NULL) {
printf ("Not able to open input file\n");
puts (sf_strerror (NULL)) ;
return 1;
}
// Say info about the input file
printf("Frames: %d\n", (int)sfinfo.frames);
printf("Samplerate: %d\n", sfinfo.samplerate);
printf("Channels: %d\n", sfinfo.channels);
sfinfo.format = filetype;
// Open output file
if((outfile = sf_open ("output.wav", SFM_WRITE, &sfinfo)) == NULL) {
printf ("Not able to open input file\n");
puts (sf_strerror (NULL)) ;
return 1;
}
// Read and filter the file
while((readcount = sf_readf_short(infile, buffer, BLOCK_SIZE)) > 0){
for(i = 0; i < readcount * 2; i += 2){
buffer[i] = filters[0].value(buffer[i]);
buffer[i+1] = filters[1].value(buffer[i+1]);
//printf("%d ", buffer[i]);
//printf("%d ", buffer[i+1]);
}
sf_writef_short(outfile, buffer, BLOCK_SIZE);
}
// Close the files
sf_close(infile);
sf_close(outfile);
return 0;
}
示例12: test_writef_short_or_die
void
test_writef_short_or_die (SNDFILE *file, int pass, short *test, sf_count_t frames, int line_num)
{ sf_count_t count ;
if ((count = sf_writef_short (file, test, frames)) != frames)
{ printf ("\n\nLine %d", line_num) ;
if (pass > 0)
printf (" (pass %d)", pass) ;
printf (" : sf_writef_short failed with short writef (%ld => %ld).\n",
SF_COUNT_TO_LONG (frames), SF_COUNT_TO_LONG (count)) ;
fflush (stdout) ;
puts (sf_strerror (file)) ;
exit (1) ;
} ;
return ;
} /* test_writef_short */
示例13: put_residue
static inline void put_residue(int16_t tx, int16_t residue)
{
int outframes;
residue_sound[residue_cur++] = tx;
residue_sound[residue_cur++] = residue;
if (residue_cur >= 8000)
{
residue_cur >>= 1;
outframes = sf_writef_short(resulthandle, residue_sound, residue_cur);
if (outframes != residue_cur)
{
fprintf(stderr, " Error writing residue sound\n");
exit(2);
}
residue_cur = 0;
}
示例14: sndfile_poll_ready_playing
static void
sndfile_poll_ready_playing (gpointer data,
gint source,
GdkInputCondition condition)
{
sndfile_driver * const d = data;
if(!d->firstpoll) {
sf_writef_short (d->outfile, d->sndbuf, d->sndbuf_size / 4);
d->playtime += (double)(d->sndbuf_size) / 4 / d->p_mixfreq;
}
d->firstpoll = FALSE;
#ifdef WORDS_BIGENDIAN
audio_mix(d->sndbuf, d->sndbuf_size / 4, d->p_mixfreq, ST_MIXER_FORMAT_S16_BE | ST_MIXER_FORMAT_STEREO);
#else
audio_mix(d->sndbuf, d->sndbuf_size / 4, d->p_mixfreq, ST_MIXER_FORMAT_S16_LE | ST_MIXER_FORMAT_STEREO);
#endif
}
示例15: complexify_tests
static void complexify_tests(void)
{
complexify_state_t *s;
complexf_t cc;
int16_t amp;
int i;
SNDFILE *outhandle;
int outframes;
int16_t out[40000];
awgn_state_t noise1;
if ((outhandle = sf_open_telephony_write(OUT_FILE_COMPLEXIFY, 2)) == NULL)
{
fprintf(stderr, " Cannot create audio file '%s'\n", OUT_FILE_COMPLEXIFY);
exit(2);
}
awgn_init_dbm0(&noise1, 1234567, -10.0f);
s = complexify_init();
for (i = 0; i < 20000; i++)
{
amp = awgn(&noise1);
cc = complexify(s, amp);
out[2*i] = cc.re;
out[2*i + 1] = cc.im;
}
awgn_release(&noise1);
complexify_free(s);
outframes = sf_writef_short(outhandle, out, 20000);
if (outframes != 20000)
{
fprintf(stderr, " Error writing audio file\n");
exit(2);
}
if (sf_close_telephony(outhandle))
{
fprintf(stderr, " Cannot close audio file '%s'\n", OUT_FILE_COMPLEXIFY);
exit(2);
}
}