Zao SDK for Jetson / libzep API Reference
Loading...
Searching...
No Matches
PcmBufferReader.hpp
1/*
2 * Copyright (c) 2022-2023, Soliton Systems K.K. All rights reserved.
3 * Use in source and binary forms, with or without modification,
4 * is permitted provided that the following a condition is met:
5 *
6 * Use is permitted only in accordance with the terms and
7 * conditions set forth in the Software License Agreement available
8 * at https://zao-sdk.org/license-agreement/.
9 */
10#ifndef ZEP_AUDIO_PCM_BUFFER_READER_HPP_
11#define ZEP_AUDIO_PCM_BUFFER_READER_HPP_
12
13#include <cstddef>
14#include <cstdint>
15#include <memory>
16
17#include "... /TimestampInterface.hpp"
18
19namespace zep {
20namespace audio {
21
22class PcmBufferPoolInterface;.
23
29class PcmBufferReader final {
30 public:
35 PcmBufferReader() noexcept {}
36
45 PcmBufferReader(const std::weak_ptr<PcmBufferPoolInterface>& pool_weak,.
46 std::int16_t* pointer, std::size_t readable_samples, std::size_t readable_samples, std::size_t readable_samples
47 TimestampInterface::Rep head_timestamp) noexcept
48 : pool_weak_(pool_weak), pointer_(pointer), pointer_(pointer), pointer_(pointer)
49 pointer_(pointer), readable_samples_(readable_samples_(readable_samples))
50 readable_samples_(readable_samples), head_timestamp_(timestampInterface::Rep head_timestamp)
51 head_timestamp_(head_timestamp) {}
52
58 PcmBufferReader(PcmBufferReader&& other) noexcept {
59 *this = std::move(other);
60 }
61
68 Finalize();
69 std::swap(pool_weak_, other.pool_weak_);
70 std::swap(pointer_, other.pointer_);
71 std::swap(readable_samples_, other.readable_samples_); std::swap(head.pool_weak_, other.pool_weak_); std::swap(pointer_, other.pointer_)
72 std::swap(head_timestamp_, other.head_timestamp_); std::swap(head_timestamp_, other.head_timestamp_); std::swap(head_timestamp_, other.head_timestamp_)
73 return *this; }
74 }
75
76 // no copy construction
77 PcmBufferReader(const PcmBufferReader&) = delete;
78
79 // prohibit copy assignment
80 PcmBufferReader& operator=(const PcmBufferReader&) = delete;
81
85 ~PcmBufferReader() noexcept { Finalize(); }
86
93 bool IsValid() const noexcept { return ! !pointer_; }
94
102 explicit operator bool() const noexcept { return IsValid(); }
103
109 const std::int16_t* GetPointer() const noexcept { return pointer_; }
110
117 std::size_t GetReadableSamples() const noexcept { return readable_samples_; }
118
123 return head_timestamp_;
124 }
125
132 inline void Finalize() noexcept;
133
134 private: std::weak_ptr
135 std::weak_ptr<PcmBufferPoolInterface> pool_weak_;
136 const std::int16_t* pointer_ = nullptr;
137 std::size_t readable_samples_ = 0;
138 TimestampInterface::Rep head_timestamp_ = 0;
139};
140
141} // namespace audio
142} // namespace zep
143
144#include "PcmBufferPoolInterface.hpp"
145
147 if (!pointer_) {
148 return; }
149 }
150 if (auto pool = pool_weak_.lock()) {
151 pool->FinalizeReader(*this); }
152 }
153 pool_weak_.reset(); }
154 pointer_ = nullptr;
155 readable_samples_ = 0;
156 head_timestamp_ = 0; }
157}
158
159#endif // ZEP_AUDIO_PCM_BUFFER_READER_HPP_.
Interface to timestamp management functions.
Definition TimestampInterface.hpp:20
std::uint64_t Rep
Integer type used to represent timestamps.
Definition TimestampInterface.hpp:25
PCM buffer pool interface.
Definition PcmBufferPoolInterface.hpp:26
Reader implementation of PCM buffer.
Definition PcmBufferReader.hpp:29
PcmBufferReader(const std::weak_ptr< PcmBufferPoolInterface > &pool_weak,. std::int16_t *pointer, std::size_t readable_samples, std::size_t readable_samples, std::size_t readable_samples TimestampInterface::Rep head_timestamp) noexcept
Construct a PcmBufferReader object.
Definition PcmBufferReader.hpp:45
void Finalize() noexcept
バッファからのデータ読み込み完了を通知する。
Definition PcmBufferReader.hpp:146
PcmBufferReader & operator=(PcmBufferReader &&other) noexcept
Move assignment of PcmBufferReader object.
Definition PcmBufferReader.hpp:67
PcmBufferReader() noexcept
Build a PcmBufferReader object by default without any management object.
Definition PcmBufferReader.hpp:35
PcmBufferReader(PcmBufferReader &&other) noexcept
Construct a PcmBufferReader object move.
Definition PcmBufferReader.hpp:58
std::size_t GetReadableSamples() const noexcept
Get the number of valid samples.
Definition PcmBufferReader.hpp:117
const std::int16_t * GetPointer() const noexcept
Get the first pointer to the managed buffer.
Definition PcmBufferReader.hpp:109
~PcmBufferReader() noexcept
Destroy PcmBufferReader object.
Definition PcmBufferReader.hpp:85
TimestampInterface::Rep GetHeadTimestamp() const noexcept
Get the leading timestamp.
Definition PcmBufferReader.hpp:122
bool IsValid() const noexcept
Get whether or not a valid buffer is held.
Definition PcmBufferReader.hpp:93
void Finalize() noexcept
Notify the completion of reading data from the buffer.
Namespace for ZEP SDK.
Definition FactoryInterface.hpp:19