/*
   HARK Library
   Copyright (C) 2021 Honda Research Institute Japan Inc.
 */

#if !defined(_HARKLIB_NODE_AUDIO_STREAM_FROM_WAVE_H_INCLUDED_)
#define _HARKLIB_NODE_AUDIO_STREAM_FROM_WAVE_H_INCLUDED_ 1

#include "hark-lib/hark-lib.h"
#include "hark-lib/node.h"

#include <iostream>

namespace hark
{
namespace node
{
    class AudioStreamFromWave: public NodeDef
    {
    public:
        AudioStreamFromWave();
        virtual void reset();
        virtual bool operator () (size_t count, InputDataBundle &input, OutputDataBundle &output);

    private:
        void initialize(std::istream &streamInput, InputDataBundle &input);
        void read_wave_header(std::istream &file, int &channels, int &bytes_per_sample, int &sampling_rate);

        std::vector<float>::iterator
        convert_bytes_to_float(std::vector<std::istream::char_type>::iterator start,
                               std::vector<std::istream::char_type>::iterator end,
                               std::vector<float>::iterator into,
                               size_t bytes_per_sample);

    private:
        // int _count;
        int _length, _advance, _channels, _bytes_per_sample, _sampling_rate;
        bool _use_wait;

        std::vector<std::istream::char_type>_buffer;
        std::vector<float>_fbuffer;
    };
}
}

#endif /* #if !defined(_HARKLIB_NODE_AUDIO_STREAM_FROM_WAVE_H_INCLUDED_) */

/* end of file */
