当前位置: 首页>>代码示例>>C++>>正文


C++ AudioProcessor::done方法代码示例

本文整理汇总了C++中AudioProcessor::done方法的典型用法代码示例。如果您正苦于以下问题:C++ AudioProcessor::done方法的具体用法?C++ AudioProcessor::done怎么用?C++ AudioProcessor::done使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AudioProcessor的用法示例。


在下文中一共展示了AudioProcessor::done方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: run

bool SndFileAudioFileReader::run(AudioProcessor& processor)
{
    if (input_file_ == nullptr) {
        return false;
    }

    const int BUFFER_SIZE = 16384;

    short input_buffer[BUFFER_SIZE];

    sf_count_t frames_to_read = BUFFER_SIZE / info_.channels;
    sf_count_t frames_read    = frames_to_read;

    sf_count_t total_frames_read = 0;

    bool success = true;

    success = processor.init(info_.samplerate, info_.channels, BUFFER_SIZE);

    if (success) {
        showProgress(0, info_.frames);

        while (success && frames_read == frames_to_read) {
            frames_read = sf_readf_short(
                input_file_,
                input_buffer,
                frames_to_read
            );

            success = processor.process(
                input_buffer,
                static_cast<int>(frames_read)
            );

            total_frames_read += frames_read;

            showProgress(total_frames_read, info_.frames);
        }

        output_stream << "\nRead " << total_frames_read << " frames\n";

        processor.done();
    }

    close();

    return success;
}
开发者ID:0xAS,项目名称:audiowaveform,代码行数:48,代码来源:SndFileAudioFileReader.cpp

示例2: run

bool SndFileAudioFileReader::run(AudioProcessor& processor)
{
    if (input_file_ == nullptr) {
        return false;
    }

    const int BUFFER_SIZE = 16384;

    float float_buffer[BUFFER_SIZE];
    short input_buffer[BUFFER_SIZE];

    const int sub_type = info_.format & SF_FORMAT_SUBMASK;

    const bool is_floating_point = sub_type == SF_FORMAT_FLOAT ||
                                   sub_type == SF_FORMAT_DOUBLE;

    sf_count_t frames_to_read = BUFFER_SIZE / info_.channels;
    sf_count_t frames_read    = frames_to_read;

    sf_count_t total_frames_read = 0;

    bool success = true;

    success = processor.init(info_.samplerate, info_.channels, BUFFER_SIZE);

    if (success) {
        showProgress(0, info_.frames);

        while (success && frames_read == frames_to_read) {
            if (is_floating_point) {
                frames_read = sf_readf_float(
                    input_file_,
                    float_buffer,
                    frames_to_read
                );

                // Scale floating-point samples from [-1.0, 1.0] to 16-bit
                // integer range. Note: we don't use SFC_SET_SCALE_FLOAT_INT_READ
                // as this scales using the overall measured waveform peak
                // amplitude, resulting in an unwanted amplitude change.

                for (int i = 0; i < frames_read * info_.channels; ++i) {
                    input_buffer[i] = static_cast<short>(
                        float_buffer[i] * std::numeric_limits<short>::max()
                    );
                }
            }
            else {
                frames_read = sf_readf_short(
                    input_file_,
                    input_buffer,
                    frames_to_read
                );
            }

            success = processor.process(
                input_buffer,
                static_cast<int>(frames_read)
            );

            total_frames_read += frames_read;

            showProgress(total_frames_read, info_.frames);
        }

        output_stream << "\nRead " << total_frames_read << " frames\n";

        processor.done();
    }

    close();

    return success;
}
开发者ID:EnochLiou,项目名称:audiowaveform,代码行数:74,代码来源:SndFileAudioFileReader.cpp

示例3: bstd_file


//.........这里部分代码省略.........
        // their mad_timer_t arguments by value!

        frame_count++;
        mad_timer_add(&timer, frame.header.duration);

        // Once decoded the frame is synthesized to PCM samples. No errors are
        // reported by mad_synth_frame();

        mad_synth_frame(&synth, &frame);

        // Synthesized samples must be converted from libmad's fixed point
        // number to the consumer format. Here we use signed 16 bit integers on
        // two channels. Integer samples are temporarily stored in a buffer that
        // is flushed when full.

        for (int i = 0; i < synth.pcm.length; i++) {
            // Left channel
            short sample = MadFixedToSshort(synth.pcm.samples[0][i]);

            *output_ptr++ = sample;

            // Right channel. If the decoded stream is monophonic then the right
            // output channel is the same as the left one.

            if (MAD_NCHANNELS(&frame.header) == 2) {
                sample = MadFixedToSshort(synth.pcm.samples[1][i]);
                *output_ptr++ = sample;
            }

            // Flush the output buffer if it is full

            if (output_ptr == output_buffer_end) {
                long pos = ftell(file_);

                showProgress(pos, file_size_);

                bool success = processor.process(
                    output_buffer,
                    OUTPUT_BUFFER_SIZE / channels
                );

                if (!success) {
                    status = STATUS_PROCESS_ERROR;
                    break;
                }

                output_ptr = output_buffer;
            }
        }
    }

    // If the output buffer is not empty and no error occurred during the last
    // write, then flush it.

    if (output_ptr != output_buffer && status != STATUS_PROCESS_ERROR) {
        int buffer_size = static_cast<int>(output_ptr - output_buffer);

        bool success = processor.process(output_buffer, buffer_size / channels);

        if (!success) {
            status = STATUS_PROCESS_ERROR;
        }
    }

    // Accounting report if no error occurred.

    if (status == STATUS_OK) {
        // Report 100% done.
        showProgress(file_size_, file_size_);

        char buffer[80];

        // The duration timer is converted to a human readable string with the
        // versatile, but still constrained mad_timer_string() function, in a
        // fashion not unlike strftime(). The main difference is that the timer
        // is broken into several values according some of its arguments. The
        // units and fracunits arguments specify the intended conversion to be
        // executed.
        //
        // The conversion unit (MAD_UNIT_MINUTES in our example) also specify
        // the order and kind of conversion specifications that can be used in
        // the format string.
        //
        // It is best to examine libmad's timer.c source-code for details of the
        // available units, fraction of units, their meanings, the format
        // arguments, etc.

        mad_timer_string(timer, buffer, "%lu:%02lu.%03u",
            MAD_UNITS_MINUTES, MAD_UNITS_MILLISECONDS, 0);

        output_stream << "\nFrames decoded: " << frame_count
                      << " (" << buffer << ")\n";
    }

    processor.done();

    close();

    return status == STATUS_OK;
}
开发者ID:EnochLiou,项目名称:audiowaveform,代码行数:101,代码来源:Mp3AudioFileReader.cpp


注:本文中的AudioProcessor::done方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。