本文整理汇总了C++中sf_writef_short函数的典型用法代码示例。如果您正苦于以下问题:C++ sf_writef_short函数的具体用法?C++ sf_writef_short怎么用?C++ sf_writef_short使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sf_writef_short函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:AbrahamJewowich,项目名称:FreeSWITCH,代码行数:53,代码来源:r2_mf_tx_tests.c
示例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
}
开发者ID:kfish,项目名称:aube,代码行数:29,代码来源:sample.c
示例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");
}
}
开发者ID:aasfalcon,项目名称:wexplorer,代码行数:32,代码来源:audiofilesndfile.cpp
示例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);
}
开发者ID:x42,项目名称:ltc-tools,代码行数:33,代码来源:ltcgen.c
示例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);
}
开发者ID:x42,项目名称:ltc-tools,代码行数:27,代码来源:ltcgen.c
示例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 */
开发者ID:ChristianFrisson,项目名称:JamomaCore,代码行数:34,代码来源:multi_file_test.c
示例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;
}
开发者ID:UIKit0,项目名称:libayemu,代码行数:26,代码来源:ayconv.c
示例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++;
}
开发者ID:marvin2k,项目名称:guibabel,代码行数:8,代码来源:DWavVault.cpp
示例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;
}
开发者ID:RobertoCarrilloAvila,项目名称:xuggle-xuggler,代码行数:55,代码来源:power_meter_tests.c
示例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;
}
开发者ID:Alberto97,项目名称:STE_av,代码行数:12,代码来源:LibsndfileSink.cpp
示例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;
}
开发者ID:eriser,项目名称:arm_synth,代码行数:49,代码来源:filter.cpp
示例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 */
开发者ID:ruthmagnus,项目名称:audacity,代码行数:17,代码来源:utils.c
示例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;
}
开发者ID:RobertoCarrilloAvila,项目名称:xuggle-xuggler,代码行数:17,代码来源:modem_echo_tests.c
示例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
}
开发者ID:elias-pschernig,项目名称:soundtracker,代码行数:20,代码来源:file-output.c
示例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);
}
}
开发者ID:odmanV2,项目名称:freecenter,代码行数:39,代码来源:line_model_tests.c
示例16: guard
void Server::mix(short* buffer, int length) {
std::lock_guard<std::mutex> guard(m_mutex);
for (int i = 0; i < length; i += 2) {
if (m_frame == 0) tick();
if (++m_frame >= m_tune->frames_per_tick) {
m_frame = 0;
if (m_playing) {
if (++m_tick >= m_ticks_per_row.val()) {
m_tick = 0;
if (++m_row >= get_max_rows(*m_tune, m_line)) {
m_row = 0;
if (!m_lineloop && (++m_line >= (int) m_tune->table.size()
|| m_tune->table[m_line] == TableLine())) {
if (m_tune->table.size() < 2) m_line = 0;
else while (--m_line > 0) { // find empty table line
if (m_tune->table[m_line - 1] == TableLine()) break;
}
}
}
}
}
}
float frame[2] = { 0, 0 };
for (int i = 0; i < CHANNEL_COUNT; i++) {
m_channels[i].add_mix(frame, m_channels[(i + CHANNEL_COUNT - 1) % CHANNEL_COUNT], m_fx);
}
m_fx.add_mix(frame);
buffer[i + 0] = clamp((int) (frame[0] * 8000), -32768, 32767);
buffer[i + 1] = clamp((int) (frame[1] * 8000), -32768, 32767);
// buffer[i + 0] = map_amp(frame[0]);
// buffer[i + 1] = map_amp(frame[1]);
}
sf_writef_short(m_log, buffer, length / 2);
}
开发者ID:2bt,项目名称:terminal-tracker,代码行数:39,代码来源:server.cpp
示例17: sndfile_file_write
static switch_status_t sndfile_file_write(switch_file_handle_t *handle, void *data, size_t *len)
{
size_t inlen = *len;
sndfile_context *context = handle->private_info;
if (switch_test_flag(handle, SWITCH_FILE_DATA_RAW)) {
*len = (size_t) sf_write_raw(context->handle, data, inlen);
} else if (switch_test_flag(handle, SWITCH_FILE_DATA_INT)) {
*len = (size_t) sf_writef_int(context->handle, (int *) data, inlen);
} else if (switch_test_flag(handle, SWITCH_FILE_DATA_SHORT)) {
*len = (size_t) sf_writef_short(context->handle, (short *) data, inlen);
} else if (switch_test_flag(handle, SWITCH_FILE_DATA_FLOAT)) {
*len = (size_t) sf_writef_float(context->handle, (float *) data, inlen);
} else if (switch_test_flag(handle, SWITCH_FILE_DATA_DOUBLE)) {
*len = (size_t) sf_writef_double(context->handle, (double *) data, inlen);
} else {
*len = (size_t) sf_writef_int(context->handle, (int *) data, inlen);
}
handle->sample_count += *len;
return sf_error(context->handle) == SF_ERR_NO_ERROR ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
}
开发者ID:crazypenguincode,项目名称:freeswitch,代码行数:23,代码来源:mod_sndfile.c
示例18: ra_sound_write
/*
* call-seq:
* snd.write(buf) => integer
*
* Writes the entire contents of the given buffer to the sound and returns the
* number of frames written.
*/
static VALUE ra_sound_write(VALUE self, VALUE buf) {
RA_SOUND *snd;
Data_Get_Struct(self, RA_SOUND, snd);
if(snd->closed) rb_raise(eRubyAudioError, "closed sound");
// Get buffer struct
RA_BUFFER *b;
Data_Get_Struct(buf, RA_BUFFER, b);
// Get info struct
SF_INFO *info;
Data_Get_Struct(snd->info, SF_INFO, info);
// Check buffer channels matches actual channels
if(b->channels != info->channels) {
rb_raise(eRubyAudioError, "channel count mismatch: %d vs %d", b->channels, info->channels);
}
// Write data
sf_count_t written;
switch(b->type) {
case RA_BUFFER_TYPE_SHORT:
written = sf_writef_short(snd->snd, b->data, b->real_size);
break;
case RA_BUFFER_TYPE_INT:
written = sf_writef_int(snd->snd, b->data, b->real_size);
break;
case RA_BUFFER_TYPE_FLOAT:
written = sf_writef_float(snd->snd, b->data, b->real_size);
break;
case RA_BUFFER_TYPE_DOUBLE:
written = sf_writef_double(snd->snd, b->data, b->real_size);
break;
}
return OFFT2NUM(written);
}
开发者ID:zmack,项目名称:ruby-audio,代码行数:44,代码来源:ra_sound.c
示例19: play_tones
static void play_tones(super_tone_tx_state_t *tone, int max_samples)
{
int16_t amp[8000];
int len;
int outframes;
int i;
int total_length;
i = 500;
total_length = 0;
do
{
len = super_tone_tx(tone, amp, 160);
outframes = sf_writef_short(outhandle, amp, len);
if (outframes != len)
{
fprintf(stderr, " Error writing audio file\n");
exit(2);
}
total_length += len;
}
while (len > 0 && --i > 0);
printf("Tone length = %d samples (%dms)\n", total_length, total_length/8);
}
开发者ID:RodrigoNieves,项目名称:FreeSWITCH,代码行数:24,代码来源:super_tone_tx_tests.c
示例20: sa_sndfile_write
static ssize_t
sa_sndfile_write( simpleaudio *sa, void *buf, size_t nframes )
{
// fprintf(stderr, "sf_write: nframes=%ld\n", nframes);
SNDFILE *s = (SNDFILE *)sa->backend_handle;
int n;
switch ( sa->format ) {
case SA_SAMPLE_FORMAT_FLOAT:
n = sf_writef_float(s, buf, nframes);
break;
case SA_SAMPLE_FORMAT_S16:
n = sf_writef_short(s, buf, nframes);
break;
default:
assert(0);
break;
}
if ( n < 0 ) {
fprintf(stderr, "sf_write: ");
sf_perror(s);
return -1;
}
return n;
}
开发者ID:TagPro-PreciousRoy,项目名称:minimodem,代码行数:24,代码来源:simpleaudio-sndfile.c
注:本文中的sf_writef_short函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论