Twitch SDK (Internal)
increasebitdepthoperator.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 OutputSampleType, typename ContextType>
33  {
34  public:
35  IncreaseBitDepthOperator(ContextType& context)
36  : mInputSource(context)
37  {
38  }
39 
40  using InputSampleType = typename InputSource::SampleType;
41  static_assert(std::is_integral<InputSampleType>::value, "Input sample type must be integral.");
42  static_assert(std::is_integral<OutputSampleType>::value, "Output sample type must be integral.");
43  static_assert(std::is_signed<InputSampleType>::value == std::is_signed<OutputSampleType>::value, "Input sample type and output sample type must have the same signedness.");
44  static_assert(sizeof(InputSampleType) < sizeof(OutputSampleType), "Output sample type must be larger than the input sample type.");
45 
46  using SampleType = OutputSampleType;
47  static constexpr size_t SampleRate = InputSource::SampleRate;
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  size_t bitsToShift = (sizeof(OutputSampleType) - sizeof(InputSampleType)) * 8;
67  return static_cast<OutputSampleType>(mInputSource[index]) << static_cast<OutputSampleType>(bitsToShift);
68  }
69 
70  private:
71  InputSource mInputSource;
72  };
73 }
Definition: increasebitdepthoperator.h:32
typename InputSource::SampleType InputSampleType
Definition: increasebitdepthoperator.h:40
IncreaseBitDepthOperator(ContextType &context)
Definition: increasebitdepthoperator.h:35
OutputSampleType SampleType
Definition: increasebitdepthoperator.h:46
JSON (JavaScript Object Notation).
Definition: adsapi.h:16
#define assert(expr)
Definition: assertion.h:47
Definition: dsputilities.h:60
SampleType operator[](size_t index) const
Definition: increasebitdepthoperator.h:61
InputSource mInputSource
Definition: increasebitdepthoperator.h:71
InputSource & GetInputSource()
Definition: increasebitdepthoperator.h:49
SampleRange GetSampleRange() const
Definition: increasebitdepthoperator.h:55
static constexpr size_t SampleRate
Definition: increasebitdepthoperator.h:47