Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
Loading...
Searching...
No Matches
I2c_Codec.h
1/*
2 * I2c_Codec.h
3 *
4 * Handle writing the registers to the TLV320AIC310x
5 * series audio codecs, used on the BeagleBone Audio Cape.
6 * This code is designed to bypass the ALSA driver and
7 * configure the codec directly in a sensible way. It
8 * is complemented by code running on the PRU which uses
9 * the McASP serial port to transfer audio data.
10 *
11 * Created on: May 25, 2014
12 * Author: Andrew McPherson
13 */
14
15#pragma once
16
17#include "AudioCodec.h"
18#include "I2c.h"
19#include <array>
20
21class I2c_Codec : public I2c, public AudioCodec
22{
23 short unsigned int pllJ;
24 short unsigned int pllD;
25 short unsigned int pllP;
26 short unsigned int pllR;
27 double PLLCLK_IN;
28public:
29 typedef enum {
30 TLV320AIC3104 = 0,
31 TLV320AIC3106,
32 } CodecType;
33
34 int writeRegister(unsigned int reg, unsigned int value);
35 int readRegister(unsigned int reg);
36
37 int initCodec();
38 int setParameters(const AudioCodecParams& codecParams);
39 AudioCodecParams getParameters();
40 int startAudio(int shouldBeReady);
41 int stopAudio();
42 unsigned int getNumIns();
43 unsigned int getNumOuts();
44 float getSampleRate();
45
46 int setPllJ(short unsigned int j);
47 int setPllD(unsigned int d);
48 int setPllP(short unsigned int p);
49 int setPllR(unsigned int r);
50 int setPllK(float k);
51 int setNcodec(double NCODEC);
52 int setAudioSamplingRate(float newSamplingRate);
53 short unsigned int getPllJ();
54 unsigned int getPllD();
55 unsigned int getPllP();
56 unsigned int getPllR();
57 float getPllK();
58 float getAudioSamplingRate();
59 int setInputGain(int channel, float gain);
60 int setDacVolume(int channel, float gain);
61 int setHpVolume(int channel, float gain);
62 int setLineOutVolume(int channel, float gain);
63 int enableHpOut(bool enable);
64 int enableLineOut(bool enable);
65 int disable();
66 int reset(){ return 0; } // Not needed for audio codec on Bela cape
67
68 void setVerbose(bool isVerbose);
69
70 I2c_Codec(int i2cBus, int I2cAddress, CodecType type, bool verbose = false);
71 ~I2c_Codec();
72
73 virtual McaspConfig& getMcaspConfig();
74 int setMode(std::string str);
75private:
76 enum {kNumIoChannels = 2};
77 int writeDacVolumeRegisters(bool mute);
78 int writeAdcVolumeRegisters(bool mute);
79 int writeOutputLevelControlReg(std::array<unsigned char,kNumIoChannels> const & regs, std::array<float,kNumIoChannels> const & volumes, unsigned char lowerHalf);
80 int writeRoutingVolumeControlReg(std::array<unsigned char,kNumIoChannels> const & regs, std::array<float,kNumIoChannels>const & volumes, bool enabled);
81 int writeHPVolumeRegisters();
82 int writeLineOutVolumeRegisters();
83protected:
84 int configureDCRemovalIIR(bool enable); //called by startAudio()
85 int codecType;
86 std::array<int,kNumIoChannels> dacVolumeHalfDbs{};
87 std::array<float,kNumIoChannels> inputGain{};
88 std::array<float,kNumIoChannels> hpVolume{};
89 std::array<float,kNumIoChannels> lineOutVolume{};
90 AudioCodecParams params;
91 McaspConfig mcaspConfig;
92 bool running;
93 bool verbose;
94 bool hpEnabled = true;
95 bool lineOutEnabled = true;
96 bool differentialInput;
97 bool unmutedPowerStage;
98 double micBias;
99 typedef enum
100 {
101 InitMode_init = 0,
102 InitMode_noDeinit = 1,
103 InitMode_noInit = 2,
104 } InitMode;
105 InitMode mode;
106};
Definition AudioCodec.h:30
Definition Mcasp.h:33
Definition AudioCodec.h:6