Twitch SDK (Internal)
converttofloatingpointoperator.h
Go to the documentation of this file.
1 /********************************************************************************************
2  * Twitch Broadcasting SDK
3  *
4  * This software is supplied under the terms of a license agreement with Twitch Interactive, Inc. and
5  * may not be copied or used except in accordance with the terms of that agreement
6  * Copyright (c) 2012-2017 Twitch Interactive, Inc.
7  *
8  *********************************************************************************************/
9 
10 #pragma once
11 
13 
14 namespace ttv
15 {
31  template <typename InputSource, typename FloatingPointType, typename ContextType>
33  {
34  public:
35  ConvertToFloatingPointOperator(ContextType& context)
36  : mInputSource(context)
37  {
38  }
39 
40  using InputSampleType = typename InputSource::SampleType;
41  static_assert(std::is_signed<InputSampleType>::value, "Input sample type must be signed.");
42  static_assert(std::is_integral<InputSampleType>::value, "Input sample type must be integral.");
43 
44  using SampleType = FloatingPointType;
45  static_assert(std::is_floating_point<SampleType>::value, "Output sample type must be floating point.");
46  static constexpr size_t SampleRate = InputSource::SampleRate;
47 
48 
49  InputSource& GetInputSource()
50  {
51  return mInputSource;
52  }
53 
54 
56  {
57  return mInputSource.GetSampleRange();
58  }
59 
60 
61  SampleType operator[](size_t index) const
62  {
63  assert(index >= GetSampleRange().startIndex);
64  assert(index < GetSampleRange().startIndex + GetSampleRange().sampleCount);
65 
66  return static_cast<SampleType>(mInputSource[index]) / static_cast<SampleType>(BisectRange<InputSampleType>());
67  }
68 
69  private:
70  InputSource mInputSource;
71  };
72 }
FloatingPointType SampleType
Definition: converttofloatingpointoperator.h:44
JSON (JavaScript Object Notation).
Definition: adsapi.h:16
#define assert(expr)
Definition: assertion.h:47
ConvertToFloatingPointOperator(ContextType &context)
Definition: converttofloatingpointoperator.h:35
static constexpr size_t SampleRate
Definition: converttofloatingpointoperator.h:46
Definition: dsputilities.h:60
SampleType operator[](size_t index) const
Definition: converttofloatingpointoperator.h:61
InputSource mInputSource
Definition: converttofloatingpointoperator.h:70
Definition: converttofloatingpointoperator.h:32
typename InputSource::SampleType InputSampleType
Definition: converttofloatingpointoperator.h:40
SampleRange GetSampleRange() const
Definition: converttofloatingpointoperator.h:55
InputSource & GetInputSource()
Definition: converttofloatingpointoperator.h:49