Twitch SDK (Internal)
converttosignedoperator.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 {
30  template <typename InputSource, typename ContextType>
32  {
33  public:
34  ConvertToSignedOperator(ContextType& context)
35  : mInputSource(context)
36  {
37  }
38 
39  using InputSampleType = typename InputSource::SampleType;
40  static_assert(std::is_unsigned<InputSampleType>::value, "Input sample type must be unsigned and integral.");
41 
42  using SampleType = std::make_signed_t<InputSampleType>;
43  static constexpr size_t SampleRate = InputSource::SampleRate;
44 
45 
46  InputSource& GetInputSource()
47  {
48  return mInputSource;
49  }
50 
51 
53  {
54  return mInputSource.GetSampleRange();
55  }
56 
57 
58  SampleType operator[](size_t index) const
59  {
60  assert(index >= GetSampleRange().startIndex);
61  assert(index < GetSampleRange().startIndex + GetSampleRange().sampleCount);
62 
63  return static_cast<SampleType>(mInputSource[index] - static_cast<InputSampleType>(BisectRange<InputSampleType>()));
64  }
65 
66  private:
67  InputSource mInputSource;
68  };
69 }
static constexpr size_t SampleRate
Definition: converttosignedoperator.h:43
InputSource & GetInputSource()
Definition: converttosignedoperator.h:46
SampleType operator[](size_t index) const
Definition: converttosignedoperator.h:58
Definition: converttosignedoperator.h:31
JSON (JavaScript Object Notation).
Definition: adsapi.h:16
#define assert(expr)
Definition: assertion.h:47
ConvertToSignedOperator(ContextType &context)
Definition: converttosignedoperator.h:34
Definition: dsputilities.h:60
InputSource mInputSource
Definition: converttosignedoperator.h:67
typename InputSource::SampleType InputSampleType
Definition: converttosignedoperator.h:39
std::make_signed_t< InputSampleType > SampleType
Definition: converttosignedoperator.h:42
SampleRange GetSampleRange() const
Definition: converttosignedoperator.h:52