Daiki Kato / EasyPlayback

Dependents:   GR-PEACH_Audio_WAV_PwmOut GR-Boards_Audio_WAV

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers EasyPlayback.h Source File

EasyPlayback.h

00001 /* mbed EasyPlayback Library
00002  * Copyright (C) 2017 dkato
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef __EASY_PLAYBACK_H__
00018 #define __EASY_PLAYBACK_H__
00019 
00020 #include <string>
00021 #include <map>
00022 #include "EasyDecoder.h"
00023 #include "AUDIO_GRBoard.h"
00024 #include "PwmOutSpeaker.h"
00025 #include "FATFileSystem.h"
00026 
00027 class EasyPlayback
00028 {
00029 public:
00030     typedef enum {
00031         AUDIO_TPYE_SSIF,
00032         AUDIO_TPYE_PWM,
00033         AUDIO_TPYE_SPDIF
00034     } audio_type_t;
00035 
00036     EasyPlayback(audio_type_t type = AUDIO_TPYE_SSIF, PinName pin1 = NC, PinName pin2 = NC);
00037     ~EasyPlayback();
00038     bool get_tag(const char* filename, char* p_title, char* p_artist, char* p_album, uint16_t tag_size);
00039     bool play(const char* filename);
00040     bool is_paused(void);
00041     void pause(void);
00042     void pause(bool type);
00043     void skip(void);
00044     bool outputVolume(float VolumeOut);
00045 
00046     template<typename T>
00047     void add_decoder(const string& extension) {
00048         m_lpDecoders[extension] = &T::inst;
00049     }
00050 
00051 private:
00052     #define AUDIO_WRITE_BUFF_NUM   (8)
00053     #define AUDIO_MSK_RING_BUFF    (AUDIO_WRITE_BUFF_NUM - 1)
00054     AUDIO_GRBoard * _audio_ssif;
00055     PwmOutSpeaker * _audio_pwm;
00056     AUDIO_RBSP * _audio;
00057     int _buff_index;
00058     audio_type_t _type;
00059     bool _skip;
00060     bool _pause;
00061     bool _init_end;
00062     uint32_t _audio_buff_size;
00063     uint8_t *_heap_buf;
00064     uint8_t *_audio_buf;
00065     std::map<std::string, EasyDecoder*(*)()> m_lpDecoders;
00066 
00067     EasyDecoder * create_decoer_class(const char* filename);
00068 };
00069 
00070 #endif