Easy playback library for AUDIO_GRBoard.

Dependents:   GR-PEACH_Audio_WAV_PwmOut GR-Boards_Audio_WAV

Committer:
dkato
Date:
Tue Jul 24 08:45:30 2018 +0000
Revision:
2:6c46c61630b3
Parent:
1:fdd79b99ba73
Add PwmOutSpeaker to output

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:9956e2ed09da 1 /* mbed EasyPlayback Library
dkato 0:9956e2ed09da 2 * Copyright (C) 2017 dkato
dkato 0:9956e2ed09da 3 *
dkato 0:9956e2ed09da 4 * Licensed under the Apache License, Version 2.0 (the "License");
dkato 0:9956e2ed09da 5 * you may not use this file except in compliance with the License.
dkato 0:9956e2ed09da 6 * You may obtain a copy of the License at
dkato 0:9956e2ed09da 7 *
dkato 0:9956e2ed09da 8 * http://www.apache.org/licenses/LICENSE-2.0
dkato 0:9956e2ed09da 9 *
dkato 0:9956e2ed09da 10 * Unless required by applicable law or agreed to in writing, software
dkato 0:9956e2ed09da 11 * distributed under the License is distributed on an "AS IS" BASIS,
dkato 0:9956e2ed09da 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
dkato 0:9956e2ed09da 13 * See the License for the specific language governing permissions and
dkato 0:9956e2ed09da 14 * limitations under the License.
dkato 0:9956e2ed09da 15 */
dkato 0:9956e2ed09da 16
dkato 0:9956e2ed09da 17 #ifndef __EASY_PLAYBACK_H__
dkato 0:9956e2ed09da 18 #define __EASY_PLAYBACK_H__
dkato 0:9956e2ed09da 19
dkato 0:9956e2ed09da 20 #include <string>
dkato 0:9956e2ed09da 21 #include <map>
dkato 0:9956e2ed09da 22 #include "EasyDecoder.h"
dkato 0:9956e2ed09da 23 #include "AUDIO_GRBoard.h"
dkato 2:6c46c61630b3 24 #include "PwmOutSpeaker.h"
dkato 1:fdd79b99ba73 25 #include "FATFileSystem.h"
dkato 0:9956e2ed09da 26
dkato 0:9956e2ed09da 27 class EasyPlayback
dkato 0:9956e2ed09da 28 {
dkato 0:9956e2ed09da 29 public:
dkato 1:fdd79b99ba73 30 typedef enum {
dkato 1:fdd79b99ba73 31 AUDIO_TPYE_SSIF,
dkato 2:6c46c61630b3 32 AUDIO_TPYE_PWM,
dkato 1:fdd79b99ba73 33 AUDIO_TPYE_SPDIF
dkato 1:fdd79b99ba73 34 } audio_type_t;
dkato 1:fdd79b99ba73 35
dkato 2:6c46c61630b3 36 EasyPlayback(audio_type_t type = AUDIO_TPYE_SSIF, PinName pin1 = NC, PinName pin2 = NC);
dkato 0:9956e2ed09da 37 ~EasyPlayback();
dkato 0:9956e2ed09da 38 bool get_tag(const char* filename, char* p_title, char* p_artist, char* p_album, uint16_t tag_size);
dkato 0:9956e2ed09da 39 bool play(const char* filename);
dkato 0:9956e2ed09da 40 bool is_paused(void);
dkato 0:9956e2ed09da 41 void pause(void);
dkato 0:9956e2ed09da 42 void pause(bool type);
dkato 0:9956e2ed09da 43 void skip(void);
dkato 0:9956e2ed09da 44 bool outputVolume(float VolumeOut);
dkato 0:9956e2ed09da 45
dkato 0:9956e2ed09da 46 template<typename T>
dkato 0:9956e2ed09da 47 void add_decoder(const string& extension) {
dkato 0:9956e2ed09da 48 m_lpDecoders[extension] = &T::inst;
dkato 0:9956e2ed09da 49 }
dkato 0:9956e2ed09da 50
dkato 0:9956e2ed09da 51 private:
dkato 0:9956e2ed09da 52 #define AUDIO_WRITE_BUFF_NUM (8)
dkato 0:9956e2ed09da 53 #define AUDIO_MSK_RING_BUFF (AUDIO_WRITE_BUFF_NUM - 1)
dkato 1:fdd79b99ba73 54 AUDIO_GRBoard * _audio_ssif;
dkato 2:6c46c61630b3 55 PwmOutSpeaker * _audio_pwm;
dkato 1:fdd79b99ba73 56 AUDIO_RBSP * _audio;
dkato 0:9956e2ed09da 57 int _buff_index;
dkato 1:fdd79b99ba73 58 audio_type_t _type;
dkato 0:9956e2ed09da 59 bool _skip;
dkato 0:9956e2ed09da 60 bool _pause;
dkato 0:9956e2ed09da 61 bool _init_end;
dkato 1:fdd79b99ba73 62 uint32_t _audio_buff_size;
dkato 0:9956e2ed09da 63 uint8_t *_heap_buf;
dkato 1:fdd79b99ba73 64 uint8_t *_audio_buf;
dkato 0:9956e2ed09da 65 std::map<std::string, EasyDecoder*(*)()> m_lpDecoders;
dkato 0:9956e2ed09da 66
dkato 0:9956e2ed09da 67 EasyDecoder * create_decoer_class(const char* filename);
dkato 0:9956e2ed09da 68 };
dkato 0:9956e2ed09da 69
dkato 0:9956e2ed09da 70 #endif