├── .gitattributes ├── .gitignore ├── .mvn └── wrapper │ └── maven-wrapper.properties ├── Dockerfile ├── Dockerfile.simple ├── README.md ├── doc.MD ├── mvnw ├── mvnw.cmd ├── pics ├── wx.jpg └── zfb.jpg ├── pom.xml ├── r1-server ├── .gitattributes ├── .mvn │ └── wrapper │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ ├── huan │ │ │ └── diy │ │ │ │ └── r1iot │ │ │ │ ├── R1IotApplication.java │ │ │ │ ├── anno │ │ │ │ ├── AIDescription.java │ │ │ │ └── AIEnums.java │ │ │ │ ├── configure │ │ │ │ ├── AuthorizationAspect.java │ │ │ │ ├── DecryptAndSavePcm.java │ │ │ │ ├── R1IotConfigure.java │ │ │ │ └── WebConfig.java │ │ │ │ ├── controller │ │ │ │ └── AdminController.java │ │ │ │ ├── dao │ │ │ │ └── LocalDeviceDao.java │ │ │ │ ├── direct │ │ │ │ ├── AIDirect.java │ │ │ │ ├── AiAssistant.java │ │ │ │ └── BoxDecision.java │ │ │ │ ├── free │ │ │ │ ├── NoAuthController.java │ │ │ │ └── TransparentProxyController.java │ │ │ │ ├── model │ │ │ │ ├── Channel.java │ │ │ │ ├── CityLocation.java │ │ │ │ ├── Device.java │ │ │ │ ├── IntentionEnum.java │ │ │ │ ├── IotAiResp.java │ │ │ │ ├── MusicAiResp.java │ │ │ │ ├── R1AdminData.java │ │ │ │ ├── R1GlobalConfig.java │ │ │ │ ├── R1Resources.java │ │ │ │ └── ServiceAliasName.java │ │ │ │ ├── service │ │ │ │ ├── DeviceService.java │ │ │ │ ├── IR1Service.java │ │ │ │ ├── IWebAlias.java │ │ │ │ ├── YoutubeService.java │ │ │ │ ├── ai │ │ │ │ │ ├── DeepSeek.java │ │ │ │ │ ├── GoogleGemini.java │ │ │ │ │ ├── GrokAiX.java │ │ │ │ │ └── IAIService.java │ │ │ │ ├── audio │ │ │ │ │ ├── IAudioService.java │ │ │ │ │ └── YoutubeAudioServiceImpl.java │ │ │ │ ├── box │ │ │ │ │ └── BoxControllerService.java │ │ │ │ ├── hass │ │ │ │ │ └── HassServiceImpl.java │ │ │ │ ├── music │ │ │ │ │ ├── GequBaoMusicImpl.java │ │ │ │ │ ├── IMusicService.java │ │ │ │ │ ├── NetEaseMusicImpl.java │ │ │ │ │ ├── VIPMusic.java │ │ │ │ │ └── YoutubeMusicImpl.java │ │ │ │ ├── news │ │ │ │ │ ├── ChinaSoundImpl.java │ │ │ │ │ └── INewsService.java │ │ │ │ ├── radio │ │ │ │ │ ├── DefaultRadioServiceImpl.java │ │ │ │ │ └── IRadioService.java │ │ │ │ └── weather │ │ │ │ │ ├── IWeatherService.java │ │ │ │ │ └── QWeatherServiceImpl.java │ │ │ │ ├── tools │ │ │ │ └── AiTools.java │ │ │ │ └── util │ │ │ │ ├── R1IotUtils.java │ │ │ │ └── TcpChannelUtils.java │ │ └── org │ │ │ └── concentus │ │ │ ├── Analysis.java │ │ │ ├── AnalysisInfo.java │ │ │ ├── ApplySineWindow.java │ │ │ ├── Arrays.java │ │ │ ├── Autocorrelation.java │ │ │ ├── BWExpander.java │ │ │ ├── Bands.java │ │ │ ├── BoxedValue.java │ │ │ ├── BurgModified.java │ │ │ ├── CNG.java │ │ │ ├── CNGState.java │ │ │ ├── CWRS.java │ │ │ ├── CeltCommon.java │ │ │ ├── CeltConstants.java │ │ │ ├── CeltDecoder.java │ │ │ ├── CeltEncoder.java │ │ │ ├── CeltLPC.java │ │ │ ├── CeltMode.java │ │ │ ├── CeltPitchXCorr.java │ │ │ ├── CeltTables.java │ │ │ ├── ChannelLayout.java │ │ │ ├── CodeSigns.java │ │ │ ├── CodecHelpers.java │ │ │ ├── CorrelateMatrix.java │ │ │ ├── DecControlState.java │ │ │ ├── DecodeAPI.java │ │ │ ├── DecodeCore.java │ │ │ ├── DecodeIndices.java │ │ │ ├── DecodeParameters.java │ │ │ ├── DecodePitch.java │ │ │ ├── DecodePulses.java │ │ │ ├── DecoderAPIFlag.java │ │ │ ├── Downmix.java │ │ │ ├── EncControlState.java │ │ │ ├── EncodeAPI.java │ │ │ ├── EncodeIndices.java │ │ │ ├── EncodePulses.java │ │ │ ├── EntropyCoder.java │ │ │ ├── FFTState.java │ │ │ ├── Filters.java │ │ │ ├── FindLPC.java │ │ │ ├── FindLTP.java │ │ │ ├── FindPitchLags.java │ │ │ ├── FindPredCoefs.java │ │ │ ├── GainQuantization.java │ │ │ ├── HPVariableCutoff.java │ │ │ ├── Inlines.java │ │ │ ├── K2A.java │ │ │ ├── Kernels.java │ │ │ ├── KissFFT.java │ │ │ ├── LPCInversePredGain.java │ │ │ ├── LTPAnalysisFilter.java │ │ │ ├── LTPScaleControl.java │ │ │ ├── Laplace.java │ │ │ ├── LinearAlgebra.java │ │ │ ├── MDCT.java │ │ │ ├── MDCTLookup.java │ │ │ ├── MLP.java │ │ │ ├── MultiLayerPerceptron.java │ │ │ ├── NLSF.java │ │ │ ├── NLSFCodebook.java │ │ │ ├── NoiseShapeAnalysis.java │ │ │ ├── OpusApplication.java │ │ │ ├── OpusBandwidth.java │ │ │ ├── OpusConstants.java │ │ │ ├── OpusDecoder.java │ │ │ ├── OpusEncoder.java │ │ │ ├── OpusError.java │ │ │ ├── OpusException.java │ │ │ ├── OpusFramesize.java │ │ │ ├── OpusMSDecoder.java │ │ │ ├── OpusMSEncoder.java │ │ │ ├── OpusMode.java │ │ │ ├── OpusMultistream.java │ │ │ ├── OpusPacketInfo.java │ │ │ ├── OpusRepacketizer.java │ │ │ ├── OpusSignal.java │ │ │ ├── OpusTables.java │ │ │ ├── PLC.java │ │ │ ├── PLCStruct.java │ │ │ ├── Pitch.java │ │ │ ├── PitchAnalysisCore.java │ │ │ ├── ProcessGains.java │ │ │ ├── PulseCache.java │ │ │ ├── QuantizeBands.java │ │ │ ├── QuantizeLTPGains.java │ │ │ ├── Rate.java │ │ │ ├── RegularizeCorrelations.java │ │ │ ├── Resampler.java │ │ │ ├── ResidualEnergy.java │ │ │ ├── Schur.java │ │ │ ├── ShellCoder.java │ │ │ ├── SideInfoIndices.java │ │ │ ├── Sigmoid.java │ │ │ ├── SilkChannelDecoder.java │ │ │ ├── SilkChannelEncoder.java │ │ │ ├── SilkConstants.java │ │ │ ├── SilkDecoder.java │ │ │ ├── SilkDecoderControl.java │ │ │ ├── SilkEncoder.java │ │ │ ├── SilkEncoderControl.java │ │ │ ├── SilkError.java │ │ │ ├── SilkLPState.java │ │ │ ├── SilkNSQState.java │ │ │ ├── SilkPrefilterState.java │ │ │ ├── SilkResamplerState.java │ │ │ ├── SilkShapeState.java │ │ │ ├── SilkTables.java │ │ │ ├── SilkVADState.java │ │ │ ├── Sort.java │ │ │ ├── SpeexResampler.java │ │ │ ├── Spread.java │ │ │ ├── Stereo.java │ │ │ ├── StereoDecodeState.java │ │ │ ├── StereoEncodeState.java │ │ │ ├── StereoWidthState.java │ │ │ ├── SumSqrShift.java │ │ │ ├── TOCStruct.java │ │ │ ├── TonalityAnalysisState.java │ │ │ ├── TuningParameters.java │ │ │ ├── VQ.java │ │ │ ├── VQ_WMat_EC.java │ │ │ ├── VoiceActivityDetection.java │ │ │ └── VorbisLayout.java │ └── resources │ │ ├── China-City-List-latest.csv │ │ ├── application.properties │ │ ├── radio.txt │ │ └── scripts │ │ └── manage_cloudflared.sh │ └── test │ └── java │ └── huan │ └── diy │ └── r1iot │ ├── AITest.java │ └── R1IotApplicationTests.java └── r1-web ├── .env.development ├── .env.production ├── README.md ├── package-lock.json ├── package.json ├── pom.xml ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── App.css ├── components │ ├── api.ts │ ├── device.tsx │ └── pop_pass.tsx ├── index.css ├── index.tsx ├── logo.svg ├── model │ └── R1AdminData.ts ├── pages │ ├── home │ │ ├── home.css │ │ └── index.tsx │ └── server │ │ ├── index.tsx │ │ └── server.css ├── react-app-env.d.ts ├── reportWebVitals.ts └── setupTests.ts ├── tsconfig.json └── yarn.lock /.gitattributes: -------------------------------------------------------------------------------- 1 | /mvnw text eol=lf 2 | *.cmd text eol=crlf 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | 35 | **/node_modules/ 36 | 37 | **/node/ 38 | **/target/ 39 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | wrapperVersion=3.3.2 18 | distributionType=only-script 19 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip 20 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # 第一阶段:构建 jar 包 2 | FROM eclipse-temurin:17.0.14_7-jdk as builder 3 | 4 | ENV MAVEN_VERSION=3.9.9 5 | ENV MAVEN_HOME=/opt/maven 6 | ENV PATH=${MAVEN_HOME}/bin:${PATH} 7 | 8 | RUN apt-get update && \ 9 | apt-get install -y curl tar && \ 10 | curl -fsSL https://downloads.apache.org/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz -o /tmp/maven.tar.gz && \ 11 | mkdir -p ${MAVEN_HOME} && \ 12 | tar -xzf /tmp/maven.tar.gz -C ${MAVEN_HOME} --strip-components=1 && \ 13 | rm -rf /tmp/maven.tar.gz && \ 14 | apt-get clean && \ 15 | rm -rf /var/lib/apt/lists/* 16 | 17 | WORKDIR /workspace 18 | COPY . . 19 | 20 | # 构建项目,生成 jar 21 | RUN mvn clean package -DskipTests 22 | 23 | # 第二阶段:运行 jar 包 24 | FROM eclipse-temurin:17.0.14_7-jdk 25 | 26 | WORKDIR /app 27 | 28 | # 安装基础工具和ffmpeg 29 | RUN apt-get update && \ 30 | apt-get install -y wget ffmpeg ca-certificates && \ 31 | apt-get clean && \ 32 | rm -rf /var/lib/apt/lists/* 33 | 34 | # 根据系统架构下载对应的 yt-dlp 和 cloudflared 二进制 35 | RUN ARCH=$(uname -m) && \ 36 | echo "检测到系统架构: $ARCH" && \ 37 | if [ "$ARCH" = "x86_64" ]; then \ 38 | # yt-dlp 39 | YT_URL="https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_linux"; \ 40 | # cloudflared 41 | CF_URL="https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb"; \ 42 | elif [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then \ 43 | YT_URL="https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_linux_aarch64"; \ 44 | CF_URL="https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-arm64.deb"; \ 45 | else \ 46 | echo "不支持的架构: $ARCH"; exit 1; \ 47 | fi && \ 48 | # 下载并安装 yt-dlp 49 | echo "下载 yt-dlp URL: $YT_URL" && \ 50 | wget "$YT_URL" -O /usr/local/bin/yt-dlp && \ 51 | chmod a+rx /usr/local/bin/yt-dlp && \ 52 | yt-dlp --version && \ 53 | # 下载并安装 cloudflared 54 | echo "下载 cloudflared URL: $CF_URL" && \ 55 | wget "$CF_URL" -O /tmp/cloudflared.deb && \ 56 | dpkg -i /tmp/cloudflared.deb || apt-get install -f -y && \ 57 | rm -f /tmp/cloudflared.deb && \ 58 | cloudflared --version 59 | 60 | # 从构建阶段复制 jar 文件 61 | COPY --from=builder /workspace/r1-server/target/*.jar app.jar 62 | 63 | COPY r1-server/src/main/resources/scripts/manage_cloudflared.sh /manage_cloudflared.sh 64 | RUN chmod +x /manage_cloudflared.sh 65 | 66 | ENTRYPOINT ["java", "-jar", "app.jar"] -------------------------------------------------------------------------------- /Dockerfile.simple: -------------------------------------------------------------------------------- 1 | FROM eclipse-temurin:17.0.14_7-jdk 2 | 3 | WORKDIR /app 4 | 5 | # 安装基础工具和ffmpeg 6 | RUN apt-get update && \ 7 | apt-get install -y wget ffmpeg ca-certificates && \ 8 | apt-get clean && \ 9 | rm -rf /var/lib/apt/lists/* 10 | 11 | # 根据系统架构下载对应的 yt-dlp 和 cloudflared 二进制 12 | RUN ARCH=$(uname -m) && \ 13 | echo "检测到系统架构: $ARCH" && \ 14 | if [ "$ARCH" = "x86_64" ]; then \ 15 | # yt-dlp 16 | YT_URL="https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_linux"; \ 17 | # cloudflared 18 | CF_URL="https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb"; \ 19 | elif [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then \ 20 | YT_URL="https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_linux_aarch64"; \ 21 | CF_URL="https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-arm64.deb"; \ 22 | else \ 23 | echo "不支持的架构: $ARCH"; exit 1; \ 24 | fi && \ 25 | # 下载并安装 yt-dlp 26 | echo "下载 yt-dlp URL: $YT_URL" && \ 27 | wget "$YT_URL" -O /usr/local/bin/yt-dlp && \ 28 | chmod a+rx /usr/local/bin/yt-dlp && \ 29 | yt-dlp --version && \ 30 | # 下载并安装 cloudflared 31 | echo "下载 cloudflared URL: $CF_URL" && \ 32 | wget "$CF_URL" -O /tmp/cloudflared.deb && \ 33 | dpkg -i /tmp/cloudflared.deb || apt-get install -f -y && \ 34 | rm -f /tmp/cloudflared.deb && \ 35 | cloudflared --version 36 | 37 | # 从构建阶段复制 jar 文件 38 | COPY r1-server/target/r1-server-0.0.1-SNAPSHOT.jar app.jar 39 | 40 | COPY r1-server/src/main/resources/scripts/manage_cloudflared.sh /manage_cloudflared.sh 41 | RUN chmod +x /manage_cloudflared.sh 42 | 43 | ENTRYPOINT ["java", "-jar", "app.jar"] 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 如果还是不会 2 | 【闲鱼】https://m.tb.cn/h.6xNUds6?tk=WqSpVnM3dKv HU287 「我在闲鱼发布了【斐讯R1音箱】」 3 | 点击链接直接打开 4 | 5 | ## Usage 6 | 7 | ``` 8 | 9 | docker run --pull=always --restart=always --name="r1" -it -d --network=host -e password=123456 -v /mnt/vda4/r1-iot/:/root/.r1-iot registry.cn-hangzhou.aliyuncs.com/ring1012/r1 10 | 11 | ``` 12 | 13 | -------------------------------------------------------------------------------- /doc.MD: -------------------------------------------------------------------------------- 1 | 2 | com.unisound.vui.engine.NativeANTEngine#doPlayTTS 3 | nluparser.scheme.Result 4 | -------------------------------------------------------------------------------- /pics/wx.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ring1012/r1-iot-java/297da76776af2cde446febc0363498f855fdd686/pics/wx.jpg -------------------------------------------------------------------------------- /pics/zfb.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ring1012/r1-iot-java/297da76776af2cde446febc0363498f855fdd686/pics/zfb.jpg -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 3.4.3 9 | 10 | 11 | huan.diy 12 | r1-iot 13 | 0.0.1-SNAPSHOT 14 | r1-iot 15 | r1-iot 16 | 17 | pom 18 | 19 | 20 | r1-server 21 | r1-web 22 | 23 | 24 | 25 | 17 26 | 27 | 28 | 29 | 30 | 31 | org.apache.maven.plugins 32 | maven-compiler-plugin 33 | 34 | 35 | 36 | org.projectlombok 37 | lombok 38 | 39 | 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-maven-plugin 45 | 46 | 47 | 48 | org.projectlombok 49 | lombok 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /r1-server/.gitattributes: -------------------------------------------------------------------------------- 1 | /mvnw text eol=lf 2 | *.cmd text eol=crlf 3 | -------------------------------------------------------------------------------- /r1-server/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | wrapperVersion=3.3.2 18 | distributionType=only-script 19 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip 20 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/R1IotApplication.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class R1IotApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(R1IotApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/anno/AIDescription.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.anno; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target(ElementType.FIELD) 10 | public @interface AIDescription { 11 | String value(); 12 | String type() default "string"; 13 | } 14 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/anno/AIEnums.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.anno; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target(ElementType.FIELD) 10 | public @interface AIEnums { 11 | String[] value() default {}; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/configure/AuthorizationAspect.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.configure; 2 | 3 | import huan.diy.r1iot.util.R1IotUtils; 4 | import jakarta.servlet.http.HttpServletRequest; 5 | import org.aspectj.lang.annotation.Aspect; 6 | import org.aspectj.lang.annotation.Before; 7 | import org.aspectj.lang.annotation.Pointcut; 8 | import org.springframework.http.HttpStatus; 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.web.server.ResponseStatusException; 11 | 12 | 13 | @Aspect 14 | @Component 15 | public class AuthorizationAspect { 16 | 17 | 18 | private final HttpServletRequest request; 19 | 20 | // 构造函数注入 HttpServletRequest 21 | public AuthorizationAspect(HttpServletRequest request) { 22 | this.request = request; 23 | } 24 | 25 | // 定义一个切入点,所有标注为 @RestController 的方法都会被拦截 26 | @Pointcut("execution(public * huan.diy.r1iot.controller..*(..))") 27 | public void restControllerMethods() {} 28 | 29 | // 在执行方法之前执行此切面,验证Authorization头 30 | @Before("restControllerMethods()") 31 | public void checkAuthorization() { 32 | String authorizationHeader = request.getHeader("Authorization"); 33 | 34 | if (authorizationHeader == null || !authorizationHeader.equals(R1IotUtils.getAuthToken())) { 35 | throw new ResponseStatusException(HttpStatus.FORBIDDEN, "Unauthorized"); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/configure/WebConfig.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.configure; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 5 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; 6 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 7 | 8 | @Configuration 9 | public class WebConfig implements WebMvcConfigurer { 10 | 11 | @Override 12 | public void addResourceHandlers(ResourceHandlerRegistry registry) { 13 | // 只处理特定的静态资源类型 14 | registry.addResourceHandler( 15 | "/", 16 | "/server", 17 | "/**/*.js", 18 | "/**/*.css", 19 | "/**/*.png", 20 | "/**/*.jpg", 21 | "/**/*.jpeg", 22 | "/**/*.gif", 23 | "/**/*.svg", 24 | "/**/*.ico", 25 | "/**/*.woff", 26 | "/**/*.ttf", 27 | "/**/*.map" 28 | ).addResourceLocations("classpath:/static/") 29 | .setCachePeriod(3600); // 缓存可选 30 | } 31 | 32 | @Override 33 | public void addViewControllers(ViewControllerRegistry registry) { 34 | // 映射根路径到 index.html 35 | registry.addViewController("/").setViewName("forward:/index.html"); 36 | // 映射 /server 到 index.html(或其他静态页面) 37 | registry.addViewController("/server").setViewName("forward:/index.html"); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/controller/AdminController.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.controller; 2 | 3 | import huan.diy.r1iot.direct.AIDirect; 4 | import huan.diy.r1iot.model.Device; 5 | import huan.diy.r1iot.model.R1AdminData; 6 | import huan.diy.r1iot.model.R1GlobalConfig; 7 | import huan.diy.r1iot.model.R1Resources; 8 | import huan.diy.r1iot.service.DeviceService; 9 | import huan.diy.r1iot.util.R1IotUtils; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.util.StringUtils; 12 | import org.springframework.web.bind.annotation.*; 13 | 14 | import java.util.List; 15 | import java.util.Optional; 16 | 17 | 18 | @RestController 19 | @RequestMapping("/admin") 20 | @CrossOrigin(origins = "*") 21 | public class AdminController { 22 | 23 | @Autowired 24 | private R1Resources r1Resources; 25 | 26 | @Autowired 27 | private R1GlobalConfig r1GlobalConfig; 28 | 29 | @Autowired 30 | private DeviceService deviceService; 31 | 32 | @Autowired 33 | private AIDirect direct; 34 | 35 | @GetMapping(value = "/resources") 36 | public R1AdminData redirect() { 37 | List devices = deviceService.listAll(); 38 | 39 | return new R1AdminData(r1Resources, devices, R1IotUtils.getCurrentDeviceId(), r1GlobalConfig); 40 | } 41 | 42 | @PostMapping("/device") 43 | public String deviceOne(@RequestBody final Device device) { 44 | int ret = deviceService.upInsert(device); 45 | if (ret == 0) { 46 | throw new RuntimeException("设备更新失败了"); 47 | } else { 48 | return "success"; 49 | } 50 | } 51 | 52 | 53 | @PostMapping("/globalConfig") 54 | public String deviceOne(@RequestBody final R1GlobalConfig req) { 55 | if (Optional.ofNullable(req.getCfServiceId()).map(a -> 56 | StringUtils.hasLength(a) && !a.equals(r1GlobalConfig.getCfServiceId())).orElse(false)) { 57 | new Thread(() -> R1IotUtils.cfInstall(req.getCfServiceId())).start(); 58 | } 59 | r1GlobalConfig.setCfServiceId(req.getCfServiceId()); 60 | r1GlobalConfig.setYtdlpEndpoint(req.getYtdlpEndpoint()); 61 | r1GlobalConfig.setHostIp(req.getHostIp()); 62 | deviceService.upInsertGlobalConfig(r1GlobalConfig); 63 | return "success"; 64 | } 65 | 66 | @DeleteMapping("/device/{deviceId}") 67 | public String deviceOne(@PathVariable final String deviceId) { 68 | deviceService.deleteById(deviceId); 69 | return "success"; 70 | } 71 | 72 | 73 | 74 | 75 | } 76 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/direct/AiAssistant.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.direct; 2 | 3 | import dev.langchain4j.agent.tool.ToolExecutionRequest; 4 | import dev.langchain4j.agent.tool.ToolSpecification; 5 | import dev.langchain4j.agent.tool.ToolSpecifications; 6 | import dev.langchain4j.data.message.*; 7 | import dev.langchain4j.memory.ChatMemory; 8 | import dev.langchain4j.model.chat.ChatLanguageModel; 9 | import dev.langchain4j.model.chat.request.ChatRequest; 10 | import dev.langchain4j.model.chat.request.ChatRequestParameters; 11 | import dev.langchain4j.model.chat.response.ChatResponse; 12 | import dev.langchain4j.service.tool.DefaultToolExecutor; 13 | import dev.langchain4j.service.tool.ToolExecutor; 14 | import huan.diy.r1iot.util.R1IotUtils; 15 | import lombok.AllArgsConstructor; 16 | import lombok.Data; 17 | import lombok.NoArgsConstructor; 18 | import lombok.extern.slf4j.Slf4j; 19 | import org.springframework.util.CollectionUtils; 20 | 21 | import java.time.DayOfWeek; 22 | import java.time.LocalDateTime; 23 | import java.time.format.DateTimeFormatter; 24 | import java.time.format.TextStyle; 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | import java.util.Locale; 28 | import java.util.UUID; 29 | 30 | import static dev.langchain4j.data.message.UserMessage.userMessage; 31 | 32 | @Data 33 | @AllArgsConstructor 34 | @NoArgsConstructor 35 | @Slf4j 36 | public class AiAssistant { 37 | 38 | private ChatLanguageModel openAiModel; 39 | private String systemPrompt; 40 | private BoxDecision boxDecision; 41 | private ChatMemory chatMemory; 42 | private boolean firstMsg; 43 | 44 | public static String now() { 45 | // 获取当前日期时间 46 | LocalDateTime now = LocalDateTime.now(); 47 | 48 | // 定义日期时间格式 49 | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH时mm分ss秒"); 50 | 51 | // 格式化日期时间 52 | String formattedDateTime = now.format(formatter); 53 | 54 | // 获取星期几 55 | DayOfWeek dayOfWeek = now.getDayOfWeek(); 56 | String weekDay = dayOfWeek.getDisplayName(TextStyle.FULL, Locale.CHINA); 57 | 58 | return "现在是" + formattedDateTime + ", " + weekDay; 59 | } 60 | 61 | public String chat(String text) { 62 | List toolSpecifications = ToolSpecifications.toolSpecificationsFrom(boxDecision); 63 | List chatMessages = chatMemory.messages(); 64 | UserMessage userMessage = userMessage(text); 65 | 66 | List reqMessages = new ArrayList<>(); 67 | if (firstMsg) { 68 | reqMessages.add(userMessage); 69 | } 70 | reqMessages.add(new SystemMessage(systemPrompt + "\n" + now() + "\n" + """ 71 | 72 | 注意: 73 | 你是一个中文助手百科全书,用简体中文回答用户的提问! 74 | """)); 75 | reqMessages.addAll(chatMessages); 76 | if (!firstMsg) { 77 | reqMessages.add(userMessage); 78 | } 79 | 80 | ChatRequest chatRequest = ChatRequest.builder() 81 | .messages(reqMessages) 82 | .parameters(ChatRequestParameters.builder() 83 | .toolSpecifications(toolSpecifications) 84 | .build()) 85 | .build(); 86 | 87 | 88 | ChatResponse chatResponse = openAiModel.chat(chatRequest); 89 | chatMessages.add(userMessage); 90 | 91 | AiMessage aiMessage = chatResponse.aiMessage(); 92 | 93 | List toolExecutionRequests = aiMessage.toolExecutionRequests(); 94 | 95 | if (CollectionUtils.isEmpty(toolExecutionRequests)) { 96 | chatMessages.add(aiMessage); 97 | return aiMessage.text().replaceAll(R1IotUtils.CHINESE, "").replaceAll("\\*\\*", ""); 98 | } 99 | var toolExecutionRequest = toolExecutionRequests.get(0); 100 | ToolExecutor toolExecutor = new DefaultToolExecutor(boxDecision, toolExecutionRequest); 101 | String result = toolExecutor.execute(toolExecutionRequest, UUID.randomUUID().toString()); 102 | ToolExecutionResultMessage toolExecutionResultMessage = ToolExecutionResultMessage.from(toolExecutionRequest, result); 103 | 104 | log.info(toolExecutionResultMessage.toString()); 105 | // chatMessages.add(toolExecutionResultMessage); 106 | 107 | return null; 108 | 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/free/NoAuthController.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.free; 2 | 3 | import huan.diy.r1iot.direct.AIDirect; 4 | import huan.diy.r1iot.service.YoutubeService; 5 | import huan.diy.r1iot.service.music.IMusicService; 6 | import huan.diy.r1iot.util.R1IotUtils; 7 | import jakarta.servlet.http.HttpServletResponse; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.web.bind.annotation.*; 10 | 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | import java.util.UUID; 14 | 15 | @RestController 16 | @CrossOrigin(origins = "*") 17 | public class NoAuthController { 18 | 19 | @Autowired 20 | private AIDirect aidirect; 21 | 22 | @Autowired 23 | private YoutubeService youtubeService; 24 | 25 | @Autowired 26 | private Map musicServiceMap; 27 | 28 | @PostMapping("/auth") 29 | public String login(@RequestBody final Map map) { 30 | String password = map.get("password"); 31 | String envPass = System.getenv("password"); 32 | if (password.equals(envPass)) { 33 | String token = UUID.randomUUID().toString(); 34 | R1IotUtils.setAuthToken(token); 35 | return token; 36 | } else { 37 | throw new RuntimeException("password does not match"); 38 | } 39 | } 40 | 41 | 42 | @GetMapping("/audio/play/{vId}.m4a") 43 | public void streamAudio(@PathVariable String vId, 44 | @RequestHeader(value = "Range", required = false) String rangeHeader, 45 | HttpServletResponse response) throws Exception { 46 | youtubeService.streamAudio(vId, rangeHeader, response); 47 | } 48 | 49 | @GetMapping("/music/{musicSvc}/{songId}.mp3") 50 | public void streamMusic(@PathVariable String musicSvc, 51 | @PathVariable String songId, 52 | HttpServletResponse response) throws Exception { 53 | musicServiceMap.get(musicSvc).streamMusic(songId, response); 54 | } 55 | 56 | 57 | @GetMapping("/test") 58 | public String test(@RequestParam String deviceId) { 59 | 60 | String resp = aidirect.getAssistants().get(deviceId).chat("我想听周杰伦的歌"); 61 | 62 | System.out.println(resp); 63 | 64 | return "success"; 65 | } 66 | 67 | @PostMapping("/getUserInfo") 68 | public Map getUserInfo() { 69 | Map map = new HashMap<>(); 70 | map.put("status", "0"); 71 | return map; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/model/Channel.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.model; 2 | 3 | public record Channel(String tvgName, String groupTitle, String id) {} 4 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/model/CityLocation.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.model; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class CityLocation { 7 | 8 | private String cityName; 9 | private String locationId; 10 | private double latitude; 11 | private double longitude; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/model/Device.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class Device { 11 | private String id; 12 | private String name; 13 | private AIConfig aiConfig; 14 | private HASSConfig hassConfig; 15 | private NewsConfig newsConfig; 16 | private MusicConfig musicConfig; 17 | private AudioConfig audioConfig; 18 | private WeatherConfig weatherConfig; 19 | 20 | // Static inner class for AIConfig 21 | @Data 22 | @AllArgsConstructor 23 | @NoArgsConstructor 24 | public static class AIConfig { 25 | private String choice; 26 | private String key; 27 | private String systemPrompt; 28 | private int chatHistoryNum; 29 | } 30 | 31 | // Static inner class for HASSConfig 32 | @Data 33 | @AllArgsConstructor 34 | @NoArgsConstructor 35 | public static class HASSConfig { 36 | private String endpoint; 37 | private String token; 38 | } 39 | 40 | // Static inner class for NewsConfig 41 | @Data 42 | @AllArgsConstructor 43 | @NoArgsConstructor 44 | public static class NewsConfig { 45 | private String choice; 46 | } 47 | 48 | // Static inner class for AIConfig 49 | @Data 50 | @AllArgsConstructor 51 | @NoArgsConstructor 52 | public static class MusicConfig { 53 | private String choice; 54 | private String endpoint; 55 | } 56 | 57 | // Static inner class for audio config 58 | @Data 59 | @AllArgsConstructor 60 | @NoArgsConstructor 61 | public static class AudioConfig { 62 | private String choice; 63 | private String endpoint; 64 | } 65 | 66 | // Static inner class for audio config 67 | @Data 68 | @AllArgsConstructor 69 | @NoArgsConstructor 70 | public static class WeatherConfig { 71 | private String choice; 72 | private String key; 73 | private String endpoint; 74 | private String locationId; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/model/IntentionEnum.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.model; 2 | 3 | public enum IntentionEnum { 4 | CHAT("chat", "cn.yunzhisheng.chat", "聊天"), 5 | SMART_HOME("smart home", "cn.yunzhisheng.setting", "智能家居"), 6 | MUSIC("music", "cn.yunzhisheng.music", "播放量音乐"), 7 | NEWS("news", "cn.yunzhisheng.news", "播放新闻"); 8 | private String name; 9 | private String serviceName; 10 | private String description; 11 | 12 | IntentionEnum(String name, String serviceName, String description) { 13 | this.name = name; 14 | this.serviceName = serviceName; 15 | this.description = description; 16 | } 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/model/IotAiResp.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.model; 2 | 3 | import huan.diy.r1iot.anno.AIDescription; 4 | import huan.diy.r1iot.anno.AIEnums; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | @Data 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | public class IotAiResp { 13 | 14 | @AIDescription("entityId of the target") 15 | private String entityId; 16 | 17 | 18 | @AIDescription("action intention of user") 19 | @AIEnums({"ON", "OFF", "QUERY"}) 20 | private String action; 21 | 22 | @AIDescription("such as: temperature") 23 | private String parameter; 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/model/MusicAiResp.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.model; 2 | 3 | import huan.diy.r1iot.anno.AIDescription; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | @Data 11 | public class MusicAiResp { 12 | @AIDescription("the author of the music") 13 | private String author; 14 | 15 | @AIDescription("the name of the music") 16 | private String musicName; 17 | 18 | @AIDescription("the keyword for searching musics") 19 | private String keyword; 20 | } 21 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/model/R1AdminData.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.List; 8 | 9 | @Data 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | public class R1AdminData { 13 | private R1Resources r1Resources; 14 | private List devices; 15 | private String currentDeviceId; 16 | private R1GlobalConfig r1GlobalConfig; 17 | } 18 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/model/R1GlobalConfig.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class R1GlobalConfig { 11 | private String hostIp; 12 | private String ytdlpEndpoint; 13 | private String cfServiceId; 14 | } 15 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/model/R1Resources.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.List; 8 | 9 | @Data 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | public class R1Resources { 13 | private List aiList; 14 | private List musicList; 15 | private List newsList; 16 | private List audioList; 17 | private List weatherList; 18 | private List cityLocations; 19 | } 20 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/model/ServiceAliasName.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class ServiceAliasName { 11 | private String serviceName; 12 | private String aliasName; 13 | } 14 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/service/DeviceService.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.service; 2 | 3 | import huan.diy.r1iot.dao.LocalDeviceDao; 4 | import huan.diy.r1iot.model.Device; 5 | import huan.diy.r1iot.model.R1GlobalConfig; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.List; 10 | 11 | @Service 12 | public class DeviceService { 13 | 14 | @Autowired 15 | private LocalDeviceDao deviceDao; 16 | 17 | public List listAll() { 18 | return deviceDao.listAll(); 19 | } 20 | 21 | public int upInsert(Device device) { 22 | return deviceDao.upInsert(device); 23 | } 24 | 25 | public int upInsertGlobalConfig(R1GlobalConfig config) { 26 | return deviceDao.upInsertGlobalConfig(config); 27 | } 28 | 29 | public int deleteById(String id) { 30 | return deviceDao.deleteById(id); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/service/IR1Service.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.service; 2 | 3 | import com.fasterxml.jackson.databind.JsonNode; 4 | 5 | public interface IR1Service { 6 | 7 | JsonNode replaceOutPut(JsonNode jsonNode, String deviceId); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/service/IWebAlias.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.service; 2 | 3 | import huan.diy.r1iot.model.ServiceAliasName; 4 | import org.springframework.stereotype.Service; 5 | 6 | import java.util.Map; 7 | 8 | public interface IWebAlias { 9 | 10 | default String getServiceName(){ 11 | return this.getClass().getAnnotation(Service.class).value(); 12 | } 13 | 14 | 15 | String getAlias(); 16 | 17 | 18 | default ServiceAliasName serviceAliasName(){ 19 | return new ServiceAliasName(getServiceName(), getAlias()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/service/ai/DeepSeek.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.service.ai; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | 6 | @Service("DeepSeek") 7 | public class DeepSeek extends GrokAiX { 8 | 9 | public DeepSeek() { 10 | this.BASE_URL = "https://api.deepseek.com"; 11 | this.MODEL = "deepseek-chat"; 12 | } 13 | 14 | @Override 15 | public String getAlias() { 16 | return "DeepSeek"; 17 | } 18 | 19 | public boolean isFirstMsg() { 20 | return true; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/service/ai/GoogleGemini.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.service.ai; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import dev.langchain4j.model.chat.ChatLanguageModel; 5 | import huan.diy.r1iot.model.Device; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | import org.springframework.web.client.RestTemplate; 10 | 11 | 12 | @Slf4j 13 | @Service("Gemini") 14 | public class GoogleGemini implements IAIService { 15 | 16 | @Autowired 17 | private RestTemplate restTemplate; 18 | 19 | @Autowired 20 | private ObjectMapper objectMapper = new ObjectMapper(); 21 | 22 | private static final String API_URL = "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key="; // 替换为实际的 API URL 23 | 24 | @Override 25 | public ChatLanguageModel buildModel(Device device) { 26 | // todo add langchain gemini dependency 27 | throw new UnsupportedOperationException("Not supported yet."); 28 | } 29 | 30 | @Override 31 | public boolean isFirstMsg() { 32 | return true; 33 | } 34 | 35 | 36 | @Override 37 | public String getAlias() { 38 | return "Gemini"; 39 | } 40 | } -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/service/ai/GrokAiX.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.service.ai; 2 | 3 | import com.fasterxml.jackson.databind.DeserializationFeature; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import dev.langchain4j.model.chat.ChatLanguageModel; 6 | import dev.langchain4j.model.openai.OpenAiChatModel; 7 | import huan.diy.r1iot.model.Device; 8 | import huan.diy.r1iot.service.IWebAlias; 9 | import lombok.extern.slf4j.Slf4j; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Service; 12 | import org.springframework.web.client.RestTemplate; 13 | 14 | 15 | @Service("Grok") 16 | @Slf4j 17 | public class GrokAiX implements IAIService, IWebAlias { 18 | protected String BASE_URL; 19 | protected String MODEL; 20 | 21 | public GrokAiX() { 22 | this.BASE_URL = "https://api.x.ai/v1"; 23 | this.MODEL = "grok-2-latest"; 24 | } 25 | 26 | @Autowired 27 | private RestTemplate restTemplate; 28 | 29 | private final ObjectMapper objectMapper = new ObjectMapper(); 30 | 31 | { 32 | objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); // 全局忽略未知字段 33 | } 34 | 35 | 36 | 37 | 38 | // @Override 39 | // public T structureResponse(List messages, String key, Class clazz) { 40 | // ObjectNode requestNode = objectMapper.createObjectNode(); 41 | // requestNode.put("model", MODEL); 42 | // requestNode.put("stream", false); 43 | // requestNode.put("temperature", 0); 44 | // ArrayNode messagesArray = objectMapper.valueToTree(messages); 45 | // 46 | // requestNode.set("messages", messagesArray); 47 | // 48 | // ObjectNode formatNode = objectMapper.createObjectNode(); 49 | // 50 | // for (Field field : clazz.getDeclaredFields()) { 51 | // ObjectNode fieldNode = objectMapper.createObjectNode(); 52 | // 53 | // // 处理AIDescription注解 54 | // AIDescription desc = field.getAnnotation(AIDescription.class); 55 | // if (desc != null) { 56 | // fieldNode.put("type", desc.type()); 57 | // fieldNode.put("description", desc.value()); 58 | // } else { 59 | // fieldNode.put("type", "string"); 60 | // } 61 | // 62 | // // 处理AIEnum注解 63 | // AIEnums enumAnnotation = field.getAnnotation(AIEnums.class); 64 | // if (enumAnnotation != null && enumAnnotation.value().length > 0) { 65 | // fieldNode.putPOJO("enum", enumAnnotation.value()); 66 | // } 67 | // 68 | // formatNode.set(field.getName(), fieldNode); 69 | // } 70 | // ObjectNode schemaNode = objectMapper.createObjectNode(); 71 | // schemaNode.put("type", "json_object"); 72 | // schemaNode.set("schema", formatNode); 73 | // requestNode.set("response_format", schemaNode); 74 | // String aiReply = responseToUser(requestNode, key); 75 | // try { 76 | // return objectMapper.readValue(aiReply, clazz); 77 | // } catch (JsonProcessingException e) { 78 | // throw new RuntimeException(e); 79 | // } 80 | // } 81 | 82 | @Override 83 | public ChatLanguageModel buildModel(Device device) { 84 | return OpenAiChatModel.builder() 85 | .baseUrl(BASE_URL) 86 | .apiKey(device.getAiConfig().getKey()) 87 | .modelName(MODEL) 88 | .strictTools(false) 89 | .build(); 90 | } 91 | 92 | @Override 93 | public boolean isFirstMsg() { 94 | return false; 95 | } 96 | 97 | 98 | @Override 99 | public String getAlias() { 100 | return "Grok"; 101 | } 102 | } -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/service/ai/IAIService.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.service.ai; 2 | 3 | import dev.langchain4j.model.chat.ChatLanguageModel; 4 | import huan.diy.r1iot.model.Device; 5 | import huan.diy.r1iot.service.IWebAlias; 6 | 7 | public interface IAIService extends IWebAlias { 8 | 9 | ChatLanguageModel buildModel(Device device); 10 | 11 | boolean isFirstMsg(); 12 | } 13 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/service/audio/IAudioService.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.service.audio; 2 | 3 | import com.fasterxml.jackson.databind.JsonNode; 4 | import huan.diy.r1iot.model.Device; 5 | import huan.diy.r1iot.service.IWebAlias; 6 | 7 | 8 | public interface IAudioService extends IWebAlias { 9 | 10 | JsonNode search(String keyword, boolean look, Device device); 11 | 12 | 13 | } 14 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/service/audio/YoutubeAudioServiceImpl.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.service.audio; 2 | 3 | import com.fasterxml.jackson.databind.JsonNode; 4 | import huan.diy.r1iot.model.Device; 5 | import huan.diy.r1iot.service.YoutubeService; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | 11 | @Service("Youtube") 12 | @Slf4j 13 | public class YoutubeAudioServiceImpl implements IAudioService { 14 | 15 | private String suffix; 16 | 17 | public YoutubeAudioServiceImpl() { 18 | this.suffix = "有声"; 19 | } 20 | 21 | @Autowired 22 | private YoutubeService youtubeService; 23 | 24 | @Override 25 | public String getAlias() { 26 | return "万能的Youtube"; 27 | } 28 | 29 | @Override 30 | public JsonNode search(String keyword, boolean look, Device device) { 31 | try { 32 | return youtubeService.search(keyword, look ? "" : suffix); 33 | } catch (Exception e) { 34 | log.error("YoutubeAudioServiceImpl search error", e); 35 | return null; 36 | } 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/service/music/IMusicService.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.service.music; 2 | 3 | import com.fasterxml.jackson.databind.JsonNode; 4 | import huan.diy.r1iot.model.Device; 5 | import huan.diy.r1iot.model.MusicAiResp; 6 | import huan.diy.r1iot.service.IWebAlias; 7 | import jakarta.servlet.http.HttpServletResponse; 8 | 9 | public interface IMusicService extends IWebAlias { 10 | 11 | JsonNode fetchMusics(MusicAiResp musicAiResp, Device device); 12 | 13 | default void streamMusic(String songId, HttpServletResponse response){} 14 | } 15 | 16 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/service/music/VIPMusic.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.service.music; 2 | 3 | import com.fasterxml.jackson.databind.JsonNode; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import com.fasterxml.jackson.databind.node.ArrayNode; 6 | import com.fasterxml.jackson.databind.node.ObjectNode; 7 | import huan.diy.r1iot.model.Device; 8 | import huan.diy.r1iot.model.MusicAiResp; 9 | import lombok.extern.slf4j.Slf4j; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.http.ResponseEntity; 12 | import org.springframework.stereotype.Service; 13 | import org.springframework.util.StringUtils; 14 | import org.springframework.web.client.RestTemplate; 15 | 16 | 17 | @Service("VIP") 18 | @Slf4j 19 | public class VIPMusic implements IMusicService { 20 | 21 | @Autowired 22 | private ObjectMapper objectMapper; 23 | 24 | @Autowired 25 | private RestTemplate restTemplate; 26 | 27 | @Override 28 | public JsonNode fetchMusics(MusicAiResp musicAiResp, Device device) { 29 | 30 | StringBuilder sb = new StringBuilder(); 31 | sb.append(StringUtils.hasLength(musicAiResp.getAuthor()) ? musicAiResp.getAuthor() : ""); 32 | sb.append(" "); 33 | sb.append(StringUtils.hasLength(musicAiResp.getMusicName()) ? musicAiResp.getMusicName() : ""); 34 | String keyword = sb.toString().trim(); 35 | if (keyword.isEmpty()) { 36 | keyword = musicAiResp.getKeyword(); 37 | } 38 | JsonNode searchRet = searchByKeyword(keyword, device); 39 | ArrayNode arrayNode = (ArrayNode) searchRet.get("data"); 40 | 41 | ArrayNode musicInfo = objectMapper.createArrayNode(); 42 | for (JsonNode node : arrayNode) { 43 | try { 44 | ObjectNode music = objectMapper.createObjectNode(); 45 | Long id = node.get("id").asLong(); 46 | music.put("id", id); 47 | music.put("title", node.get("name").asText()); 48 | music.put("artist", node.get("artists").get(0).get("name").asText()); 49 | music.put("album", node.get("album").get("name").asText()); 50 | music.put("url", node.get("url").asText()); 51 | musicInfo.add(music); 52 | } catch (Exception e) { 53 | log.error(e.getMessage(), e); 54 | } 55 | 56 | } 57 | 58 | 59 | ObjectNode result = objectMapper.createObjectNode(); 60 | 61 | ObjectNode ret = objectMapper.createObjectNode(); 62 | ret.put("count", arrayNode.size()); 63 | ret.set("musicinfo", musicInfo); 64 | ret.put("pagesize", String.valueOf(arrayNode.size())); 65 | ret.put("errorCode", 0); 66 | ret.put("page", "1"); 67 | ret.put("source", 1); 68 | 69 | result.set("result", ret); 70 | 71 | return result; 72 | } 73 | 74 | 75 | public JsonNode searchByKeyword(String keyword, Device device) { 76 | String endpoint = device.getMusicConfig().getEndpoint(); 77 | endpoint = endpoint.endsWith("/") ? endpoint : (endpoint + "/"); 78 | 79 | ResponseEntity response = restTemplate.getForEntity( 80 | endpoint + "/api/search?keyword=" + keyword, 81 | JsonNode.class 82 | ); 83 | 84 | return response.getBody(); 85 | } 86 | 87 | @Override 88 | public String getAlias() { 89 | return "VIP解锁"; 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/service/news/ChinaSoundImpl.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.service.news; 2 | 3 | import com.fasterxml.jackson.databind.JsonNode; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import com.fasterxml.jackson.databind.node.ArrayNode; 6 | import com.fasterxml.jackson.databind.node.ObjectNode; 7 | import huan.diy.r1iot.model.Device; 8 | import huan.diy.r1iot.service.IWebAlias; 9 | import lombok.extern.slf4j.Slf4j; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.http.HttpEntity; 12 | import org.springframework.http.HttpHeaders; 13 | import org.springframework.http.MediaType; 14 | import org.springframework.http.ResponseEntity; 15 | import org.springframework.stereotype.Service; 16 | import org.springframework.web.client.RestTemplate; 17 | 18 | import java.util.HashMap; 19 | import java.util.Map; 20 | 21 | @Service("chinaSound") 22 | @Slf4j 23 | public class ChinaSoundImpl implements INewsService, IWebAlias { 24 | 25 | @Autowired 26 | private RestTemplate restTemplate; 27 | 28 | @Autowired 29 | private ObjectMapper objectMapper; 30 | 31 | @Override 32 | public String getAlias() { 33 | return "中国之声"; 34 | } 35 | 36 | @Override 37 | public JsonNode fetchNews(String userInput, Device device) { 38 | // API地址 39 | String url = "https://apppc.cnr.cn/cnr45609411d2c5a16/e281277129d478c12c2ed58e84ca906b/f76a0411ae1ff31be9f9e28f0b51348b"; 40 | 41 | // 构建请求体 42 | Map requestBody = new HashMap<>(); 43 | requestBody.put("chanId", "64"); // 中国之声频道ID 44 | requestBody.put("pageIndex", 1); // 第一页 45 | requestBody.put("perPage", 40); // 每页20条 46 | requestBody.put("lastNewsId", "0"); 47 | requestBody.put("docPubTime", ""); 48 | 49 | // 设置请求头 50 | HttpHeaders headers = new HttpHeaders(); 51 | headers.setContentType(MediaType.APPLICATION_JSON); 52 | 53 | // 创建请求实体 54 | HttpEntity> requestEntity = new HttpEntity<>(requestBody, headers); 55 | JsonNode directNews; 56 | try { 57 | // 发送POST请求 58 | ResponseEntity response = restTemplate.postForEntity(url, requestEntity, String.class); 59 | 60 | // 将响应内容转换为JsonNode 61 | directNews = objectMapper.readTree(response.getBody()); 62 | } catch (Exception e) { 63 | throw new RuntimeException(e); 64 | } 65 | 66 | ArrayNode arrayNode = (ArrayNode) directNews.get("data").get("categories").get(0).get("detail"); 67 | 68 | ArrayNode musicInfo = objectMapper.createArrayNode(); 69 | int index = 0; 70 | for (JsonNode node : arrayNode) { 71 | try { 72 | String link = node.get("other_info9").asText(); 73 | if (link.contains("m3u8")) { 74 | continue; 75 | } 76 | ObjectNode music = objectMapper.createObjectNode(); 77 | music.put("id", index++); 78 | music.put("title", "新闻"); 79 | music.put("artist", "中国之声"); 80 | music.put("url", link); 81 | musicInfo.add(music); 82 | } catch (Exception e) { 83 | log.error(e.getMessage(), e); 84 | } 85 | 86 | } 87 | 88 | 89 | ObjectNode result = objectMapper.createObjectNode(); 90 | 91 | ObjectNode ret = objectMapper.createObjectNode(); 92 | ret.put("count", arrayNode.size()); 93 | ret.set("musicinfo", musicInfo); 94 | ret.put("pagesize", String.valueOf(arrayNode.size())); 95 | ret.put("errorCode", 0); 96 | ret.put("page", "1"); 97 | ret.put("source", 1); 98 | 99 | result.set("result", ret); 100 | 101 | return result; 102 | 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/service/news/INewsService.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.service.news; 2 | 3 | import com.fasterxml.jackson.databind.JsonNode; 4 | import huan.diy.r1iot.model.Device; 5 | 6 | public interface INewsService { 7 | JsonNode fetchNews(String userInput, Device device); 8 | } 9 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/service/radio/IRadioService.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.service.radio; 2 | 3 | import com.fasterxml.jackson.databind.JsonNode; 4 | import huan.diy.r1iot.model.Device; 5 | 6 | public interface IRadioService { 7 | 8 | JsonNode fetchRadio(String radioName, String province, Device device); 9 | 10 | 11 | } 12 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/service/weather/IWeatherService.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.service.weather; 2 | 3 | import huan.diy.r1iot.model.Device; 4 | import huan.diy.r1iot.service.IWebAlias; 5 | 6 | public interface IWeatherService extends IWebAlias { 7 | 8 | String getWeather(String locationName, int offsetDay, Device device); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/tools/AiTools.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.tools; 2 | 3 | import dev.langchain4j.agent.tool.Tool; 4 | 5 | public class AiTools { 6 | 7 | @Tool 8 | public String hello(String name) { 9 | return "Hello " + name + "!"; 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /r1-server/src/main/java/huan/diy/r1iot/util/TcpChannelUtils.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot.util; 2 | 3 | 4 | public class TcpChannelUtils { 5 | // 远程服务器地址 6 | public static final String REMOTE_HOST = "39.105.252.245"; // 目标服务器 IP 7 | public static final int REMOTE_PORT = 80; // 远程服务器的端口 8 | } -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/AnalysisInfo.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2008 CSIRO 2 | Copyright (c) 2007-2011 Xiph.Org Foundation 3 | Originally written by Jean-Marc Valin, Gregory Maxwell, Koen Vos, 4 | Timothy B. Terriberry, and the Opus open-source contributors 5 | Ported to Java by Logan Stromberg 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 19 | names of specific contributors, may be used to endorse or promote 20 | products derived from this software without specific prior written 21 | permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 27 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | package org.concentus; 36 | 37 | class AnalysisInfo { 38 | 39 | boolean enabled = false; 40 | int valid = 0; 41 | float tonality = 0; 42 | float tonality_slope = 0; 43 | float noisiness = 0; 44 | float activity = 0; 45 | float music_prob = 0; 46 | int bandwidth = 0; 47 | 48 | AnalysisInfo() { 49 | } 50 | 51 | void Assign(AnalysisInfo other) { 52 | this.valid = other.valid; 53 | this.tonality = other.tonality; 54 | this.tonality_slope = other.tonality_slope; 55 | this.noisiness = other.noisiness; 56 | this.activity = other.activity; 57 | this.music_prob = other.music_prob; 58 | this.bandwidth = other.bandwidth; 59 | } 60 | 61 | void Reset() { 62 | valid = 0; 63 | tonality = 0; 64 | tonality_slope = 0; 65 | noisiness = 0; 66 | activity = 0; 67 | music_prob = 0; 68 | bandwidth = 0; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/BWExpander.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006-2011 Skype Limited. All Rights Reserved 2 | Ported to Java by Logan Stromberg 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 16 | names of specific contributors, may be used to endorse or promote 17 | products derived from this software without specific prior written 18 | permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.concentus; 33 | 34 | class BWExpander { 35 | 36 | /// 37 | /// Chirp (bw expand) LP AR filter (Fixed point implementation) 38 | /// 39 | /// I/O AR filter to be expanded (without leading 1) 40 | /// I length of ar 41 | /// I chirp factor (typically in range (0..1) ) 42 | static void silk_bwexpander_32( 43 | int[] ar, /* I/O AR filter to be expanded (without leading 1) */ 44 | int d, /* I Length of ar */ 45 | int chirp_Q16 /* I Chirp factor in Q16 */ 46 | ) { 47 | int i; 48 | int chirp_minus_one_Q16 = chirp_Q16 - 65536; 49 | 50 | for (i = 0; i < d - 1; i++) { 51 | ar[i] = Inlines.silk_SMULWW(chirp_Q16, ar[i]); 52 | chirp_Q16 += Inlines.silk_RSHIFT_ROUND(Inlines.silk_MUL(chirp_Q16, chirp_minus_one_Q16), 16); 53 | } 54 | ar[d - 1] = Inlines.silk_SMULWW(chirp_Q16, ar[d - 1]); 55 | } 56 | 57 | /// 58 | /// Chirp (bw expand) LP AR filter (Fixed point implementation) 59 | /// 60 | /// I/O AR filter to be expanded (without leading 1) 61 | /// I length of ar 62 | /// I chirp factor (typically in range (0..1) ) 63 | static void silk_bwexpander( 64 | short[] ar, 65 | int d, 66 | int chirp_Q16) { 67 | int i; 68 | int chirp_minus_one_Q16 = chirp_Q16 - 65536; 69 | 70 | /* NB: Dont use silk_SMULWB, instead of silk_RSHIFT_ROUND( silk_MUL(), 16 ), below. */ 71 | /* Bias in silk_SMULWB can lead to unstable filters */ 72 | for (i = 0; i < d - 1; i++) { 73 | ar[i] = (short) Inlines.silk_RSHIFT_ROUND(Inlines.silk_MUL(chirp_Q16, ar[i]), 16); 74 | chirp_Q16 += Inlines.silk_RSHIFT_ROUND(Inlines.silk_MUL(chirp_Q16, chirp_minus_one_Q16), 16); 75 | } 76 | ar[d - 1] = (short) Inlines.silk_RSHIFT_ROUND(Inlines.silk_MUL(chirp_Q16, ar[d - 1]), 16); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/BoxedValue.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2016 Logan Stromberg 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | - Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | - Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 15 | names of specific contributors, may be used to endorse or promote 16 | products derived from this software without specific prior written 17 | permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 23 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | package org.concentus; 32 | 33 | class BoxedValueByte { 34 | 35 | public byte Val; 36 | 37 | public BoxedValueByte(byte v) { 38 | Val = v; 39 | } 40 | } 41 | 42 | class BoxedValueShort { 43 | 44 | public short Val; 45 | 46 | public BoxedValueShort(short v) { 47 | Val = v; 48 | } 49 | } 50 | 51 | class BoxedValueInt { 52 | 53 | public int Val; 54 | 55 | public BoxedValueInt(int v) { 56 | Val = v; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/CNGState.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006-2011 Skype Limited. All Rights Reserved 2 | Ported to Java by Logan Stromberg 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 16 | names of specific contributors, may be used to endorse or promote 17 | products derived from this software without specific prior written 18 | permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.concentus; 33 | 34 | /// 35 | /// Struct for CNG 36 | /// 37 | class CNGState { 38 | 39 | final int[] CNG_exc_buf_Q14 = new int[SilkConstants.MAX_FRAME_LENGTH]; 40 | final short[] CNG_smth_NLSF_Q15 = new short[SilkConstants.MAX_LPC_ORDER]; 41 | final int[] CNG_synth_state = new int[SilkConstants.MAX_LPC_ORDER]; 42 | int CNG_smth_Gain_Q16 = 0; 43 | int rand_seed = 0; 44 | int fs_kHz = 0; 45 | 46 | void Reset() { 47 | Arrays.MemSet(CNG_exc_buf_Q14, 0, SilkConstants.MAX_FRAME_LENGTH); 48 | Arrays.MemSet(CNG_smth_NLSF_Q15, (short) 0, SilkConstants.MAX_LPC_ORDER); 49 | Arrays.MemSet(CNG_synth_state, 0, SilkConstants.MAX_LPC_ORDER); 50 | CNG_smth_Gain_Q16 = 0; 51 | rand_seed = 0; 52 | fs_kHz = 0; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/CeltConstants.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2008 CSIRO 2 | Copyright (c) 2007-2011 Xiph.Org Foundation 3 | Originally written by Jean-Marc Valin, Gregory Maxwell, Koen Vos, 4 | Timothy B. Terriberry, and the Opus open-source contributors 5 | Ported to Java by Logan Stromberg 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 19 | names of specific contributors, may be used to endorse or promote 20 | products derived from this software without specific prior written 21 | permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 27 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | package org.concentus; 36 | 37 | class CeltConstants { 38 | 39 | public static final int Q15ONE = 32767; 40 | 41 | public static final float CELT_SIG_SCALE = 32768.0f; 42 | 43 | public static final int SIG_SHIFT = 12; 44 | 45 | public static final int NORM_SCALING = 16384; 46 | 47 | public static final int DB_SHIFT = 10; 48 | 49 | public static final int EPSILON = 1; 50 | public static final int VERY_SMALL = 0; 51 | public static final short VERY_LARGE16 = ((short) 32767); 52 | public static final short Q15_ONE = ((short) 32767); 53 | 54 | public static final int COMBFILTER_MAXPERIOD = 1024; 55 | public static final int COMBFILTER_MINPERIOD = 15; 56 | 57 | // from opus_decode.c 58 | public static final int DECODE_BUFFER_SIZE = 2048; 59 | 60 | // from modes.c 61 | /* Alternate tuning (partially derived from Vorbis) */ 62 | public static final int BITALLOC_SIZE = 11; 63 | public static final int MAX_PERIOD = 1024; 64 | 65 | // from static_modes_float.h 66 | public static final int TOTAL_MODES = 1; 67 | 68 | // from rate.h 69 | public static final int MAX_PSEUDO = 40; 70 | public static final int LOG_MAX_PSEUDO = 6; 71 | 72 | public static final int CELT_MAX_PULSES = 128; 73 | 74 | public static final int MAX_FINE_BITS = 8; 75 | 76 | public static final int FINE_OFFSET = 21; 77 | public static final int QTHETA_OFFSET = 4; 78 | public static final int QTHETA_OFFSET_TWOPHASE = 16; 79 | 80 | /* The maximum pitch lag to allow in the pitch-based PLC. It's possible to save 81 | CPU time in the PLC pitch search by making this smaller than MAX_PERIOD. The 82 | current value corresponds to a pitch of 66.67 Hz. */ 83 | public static final int PLC_PITCH_LAG_MAX = 720; 84 | 85 | /* The minimum pitch lag to allow in the pitch-based PLC. This corresponds to a 86 | pitch of 480 Hz. */ 87 | public static final int PLC_PITCH_LAG_MIN = 100; 88 | 89 | public static final int LPC_ORDER = 24; 90 | } 91 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/CeltMode.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2008 CSIRO 2 | Copyright (c) 2007-2011 Xiph.Org Foundation 3 | Originally written by Jean-Marc Valin, Gregory Maxwell, Koen Vos, 4 | Timothy B. Terriberry, and the Opus open-source contributors 5 | Ported to Java by Logan Stromberg 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 19 | names of specific contributors, may be used to endorse or promote 20 | products derived from this software without specific prior written 21 | permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 27 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | package org.concentus; 36 | 37 | class CeltMode { 38 | 39 | int Fs = 0; 40 | int overlap = 0; 41 | 42 | int nbEBands = 0; 43 | int effEBands = 0; 44 | int[] preemph = {0, 0, 0, 0}; 45 | 46 | /// 47 | /// Definition for each "pseudo-critical band" 48 | /// 49 | short[] eBands = null; 50 | 51 | int maxLM = 0; 52 | int nbShortMdcts = 0; 53 | int shortMdctSize = 0; 54 | 55 | /// 56 | /// Number of lines in allocVectors 57 | /// 58 | int nbAllocVectors = 0; 59 | 60 | /// 61 | /// Number of bits in each band for several rates 62 | /// 63 | short[] allocVectors = null; 64 | short[] logN = null; 65 | 66 | int[] window = null; 67 | MDCTLookup mdct = new MDCTLookup(); 68 | PulseCache cache = new PulseCache(); 69 | 70 | private CeltMode() { 71 | } 72 | 73 | static final CeltMode mode48000_960_120 = new CeltMode(); 74 | 75 | static { 76 | mode48000_960_120.Fs = 48000; 77 | mode48000_960_120.overlap = 120; 78 | mode48000_960_120.nbEBands = 21; 79 | mode48000_960_120.effEBands = 21; 80 | mode48000_960_120.preemph = new int[]{27853, 0, 4096, 8192}; 81 | mode48000_960_120.eBands = CeltTables.eband5ms; 82 | mode48000_960_120.maxLM = 3; 83 | mode48000_960_120.nbShortMdcts = 8; 84 | mode48000_960_120.shortMdctSize = 120; 85 | mode48000_960_120.nbAllocVectors = 11; 86 | mode48000_960_120.allocVectors = CeltTables.band_allocation; 87 | mode48000_960_120.logN = CeltTables.logN400; 88 | mode48000_960_120.window = CeltTables.window120; 89 | mode48000_960_120.mdct = new MDCTLookup(); 90 | 91 | mode48000_960_120.mdct.n = 1920; 92 | mode48000_960_120.mdct.maxshift = 3; 93 | mode48000_960_120.mdct.kfft = new FFTState[]{ 94 | CeltTables.fft_state48000_960_0, 95 | CeltTables.fft_state48000_960_1, 96 | CeltTables.fft_state48000_960_2, 97 | CeltTables.fft_state48000_960_3,}; 98 | 99 | mode48000_960_120.mdct.trig = CeltTables.mdct_twiddles960; 100 | mode48000_960_120.cache = new PulseCache(); 101 | mode48000_960_120.cache.size = 392; 102 | mode48000_960_120.cache.index = CeltTables.cache_index50; 103 | mode48000_960_120.cache.bits = CeltTables.cache_bits50; 104 | mode48000_960_120.cache.caps = CeltTables.cache_caps50; 105 | } 106 | ; 107 | } 108 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/ChannelLayout.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2008 CSIRO 2 | Copyright (c) 2007-2011 Xiph.Org Foundation 3 | Originally written by Jean-Marc Valin, Gregory Maxwell, Koen Vos, 4 | Timothy B. Terriberry, and the Opus open-source contributors 5 | Ported to Java by Logan Stromberg 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 19 | names of specific contributors, may be used to endorse or promote 20 | products derived from this software without specific prior written 21 | permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 27 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | package org.concentus; 36 | 37 | class ChannelLayout { 38 | 39 | int nb_channels; 40 | int nb_streams; 41 | int nb_coupled_streams; 42 | final short[] mapping = new short[256]; 43 | 44 | void Reset() { 45 | nb_channels = 0; 46 | nb_streams = 0; 47 | nb_coupled_streams = 0; 48 | Arrays.MemSet(mapping, (short) 0); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/DecControlState.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006-2011 Skype Limited. All Rights Reserved 2 | Ported to Java by Logan Stromberg 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 16 | names of specific contributors, may be used to endorse or promote 17 | products derived from this software without specific prior written 18 | permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.concentus; 33 | 34 | /// 35 | /// Structure for controlling decoder operation and reading decoder status 36 | /// 37 | class DecControlState { 38 | 39 | /* I: Number of channels; 1/2 */ 40 | int nChannelsAPI = 0; 41 | 42 | /* I: Number of channels; 1/2 */ 43 | int nChannelsInternal = 0; 44 | 45 | /* I: Output signal sampling rate in Hertz; 8000/12000/16000/24000/32000/44100/48000 */ 46 | int API_sampleRate = 0; 47 | 48 | /* I: Internal sampling rate used, in Hertz; 8000/12000/16000 */ 49 | int internalSampleRate = 0; 50 | 51 | /* I: Number of samples per packet in milliseconds; 10/20/40/60 */ 52 | int payloadSize_ms = 0; 53 | 54 | /* O: Pitch lag of previous frame (0 if unvoiced), measured in samples at 48 kHz */ 55 | int prevPitchLag = 0; 56 | 57 | void Reset() { 58 | nChannelsAPI = 0; 59 | nChannelsInternal = 0; 60 | API_sampleRate = 0; 61 | internalSampleRate = 0; 62 | payloadSize_ms = 0; 63 | prevPitchLag = 0; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/DecodePitch.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006-2011 Skype Limited. All Rights Reserved 2 | Ported to Java by Logan Stromberg 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 16 | names of specific contributors, may be used to endorse or promote 17 | products derived from this software without specific prior written 18 | permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.concentus; 33 | 34 | class DecodePitch { 35 | 36 | static void silk_decode_pitch( 37 | short lagIndex, /* I */ 38 | byte contourIndex, /* O */ 39 | int[] pitch_lags, /* O 4 pitch values */ 40 | int Fs_kHz, /* I sampling frequency (kHz) */ 41 | int nb_subfr /* I number of sub frames */ 42 | ) { 43 | int lag, k, min_lag, max_lag; 44 | byte[][] Lag_CB_ptr; 45 | 46 | if (Fs_kHz == 8) { 47 | if (nb_subfr == SilkConstants.PE_MAX_NB_SUBFR) { 48 | Lag_CB_ptr = SilkTables.silk_CB_lags_stage2; 49 | } else { 50 | Inlines.OpusAssert(nb_subfr == SilkConstants.PE_MAX_NB_SUBFR >> 1); 51 | Lag_CB_ptr = SilkTables.silk_CB_lags_stage2_10_ms; 52 | } 53 | } else if (nb_subfr == SilkConstants.PE_MAX_NB_SUBFR) { 54 | Lag_CB_ptr = SilkTables.silk_CB_lags_stage3; 55 | } else { 56 | Inlines.OpusAssert(nb_subfr == SilkConstants.PE_MAX_NB_SUBFR >> 1); 57 | Lag_CB_ptr = SilkTables.silk_CB_lags_stage3_10_ms; 58 | } 59 | 60 | min_lag = Inlines.silk_SMULBB(SilkConstants.PE_MIN_LAG_MS, Fs_kHz); 61 | max_lag = Inlines.silk_SMULBB(SilkConstants.PE_MAX_LAG_MS, Fs_kHz); 62 | lag = min_lag + lagIndex; 63 | 64 | for (k = 0; k < nb_subfr; k++) { 65 | pitch_lags[k] = lag + Lag_CB_ptr[k][contourIndex]; 66 | pitch_lags[k] = Inlines.silk_LIMIT(pitch_lags[k], min_lag, max_lag); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/DecoderAPIFlag.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006-2011 Skype Limited. All Rights Reserved 2 | Ported to Java by Logan Stromberg 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 16 | names of specific contributors, may be used to endorse or promote 17 | products derived from this software without specific prior written 18 | permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.concentus; 33 | 34 | class DecoderAPIFlag { 35 | 36 | public static final int FLAG_DECODE_NORMAL = 0; 37 | public static final int FLAG_PACKET_LOST = 1; 38 | public static final int FLAG_DECODE_LBRR = 2; 39 | } 40 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/Downmix.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2008 CSIRO 2 | Copyright (c) 2007-2011 Xiph.Org Foundation 3 | Originally written by Jean-Marc Valin, Gregory Maxwell, Koen Vos, 4 | Timothy B. Terriberry, and the Opus open-source contributors 5 | Ported to Java by Logan Stromberg 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 19 | names of specific contributors, may be used to endorse or promote 20 | products derived from this software without specific prior written 21 | permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 27 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | package org.concentus; 36 | 37 | class Downmix { 38 | 39 | /// 40 | /// 41 | /// 42 | /// The type of signal being handled (either short or float) 43 | /// 44 | /// 45 | /// 46 | /// 47 | /// 48 | /// 49 | /// 50 | static void downmix_int(short[] x, int x_ptr, int[] sub, int sub_ptr, int subframe, int offset, int c1, int c2, int C) { 51 | int scale; 52 | int j; 53 | for (j = 0; j < subframe; j++) { 54 | sub[j + sub_ptr] = x[(j + offset) * C + c1]; 55 | } 56 | if (c2 > -1) { 57 | for (j = 0; j < subframe; j++) { 58 | sub[j + sub_ptr] += x[(j + offset) * C + c2]; 59 | } 60 | } else if (c2 == -2) { 61 | int c; 62 | for (c = 1; c < C; c++) { 63 | for (j = 0; j < subframe; j++) { 64 | sub[j + sub_ptr] += x[(j + offset) * C + c]; 65 | } 66 | } 67 | } 68 | scale = (1 << CeltConstants.SIG_SHIFT); 69 | if (C == -2) { 70 | scale /= C; 71 | } else { 72 | scale /= 2; 73 | } 74 | for (j = 0; j < subframe; j++) { 75 | sub[j + sub_ptr] *= scale; 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/FFTState.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2003-2004, Mark Borgerding 2 | Copyright (c) 2007-2008 CSIRO 3 | Copyright (c) 2007-2011 Xiph.Org Foundation 4 | Modified from KISS-FFT by Jean-Marc Valin 5 | Ported to Java by Logan Stromberg 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 19 | names of specific contributors, may be used to endorse or promote 20 | products derived from this software without specific prior written 21 | permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 27 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | package org.concentus; 36 | 37 | class FFTState { 38 | 39 | int nfft = 0; 40 | short scale = 0; 41 | int scale_shift = 0; 42 | int shift = 0; 43 | short[] factors = new short[2 * KissFFT.MAXFACTORS]; 44 | short[] bitrev = null; 45 | short[] twiddles = null; 46 | } 47 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/K2A.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006-2011 Skype Limited. All Rights Reserved 2 | Ported to Java by Logan Stromberg 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 16 | names of specific contributors, may be used to endorse or promote 17 | products derived from this software without specific prior written 18 | permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.concentus; 33 | 34 | class K2A { 35 | 36 | /* Step up function, converts reflection coefficients to prediction coefficients */ 37 | static void silk_k2a( 38 | int[] A_Q24, /* O Prediction coefficients [order] Q24 */ 39 | short[] rc_Q15, /* I Reflection coefficients [order] Q15 */ 40 | int order /* I Prediction order */ 41 | ) { 42 | int k, n; 43 | int[] Atmp = new int[SilkConstants.SILK_MAX_ORDER_LPC]; 44 | 45 | for (k = 0; k < order; k++) { 46 | for (n = 0; n < k; n++) { 47 | Atmp[n] = A_Q24[n]; 48 | } 49 | for (n = 0; n < k; n++) { 50 | A_Q24[n] = Inlines.silk_SMLAWB(A_Q24[n], Inlines.silk_LSHIFT(Atmp[k - n - 1], 1), rc_Q15[k]); 51 | } 52 | A_Q24[k] = 0 - Inlines.silk_LSHIFT((int) rc_Q15[k], 9); 53 | } 54 | } 55 | 56 | /* Step up function, converts reflection coefficients to prediction coefficients */ 57 | static void silk_k2a_Q16( 58 | int[] A_Q24, /* O Prediction coefficients [order] Q24 */ 59 | int[] rc_Q16, /* I Reflection coefficients [order] Q16 */ 60 | int order /* I Prediction order */ 61 | ) { 62 | int k, n; 63 | int[] Atmp = new int[SilkConstants.SILK_MAX_ORDER_LPC]; 64 | 65 | for (k = 0; k < order; k++) { 66 | for (n = 0; n < k; n++) { 67 | Atmp[n] = A_Q24[n]; 68 | } 69 | for (n = 0; n < k; n++) { 70 | A_Q24[n] = Inlines.silk_SMLAWW(A_Q24[n], Atmp[k - n - 1], rc_Q16[k]); 71 | } 72 | A_Q24[k] = 0 - Inlines.silk_LSHIFT(rc_Q16[k], 8); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/LTPScaleControl.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006-2011 Skype Limited. All Rights Reserved 2 | Ported to Java by Logan Stromberg 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 16 | names of specific contributors, may be used to endorse or promote 17 | products derived from this software without specific prior written 18 | permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.concentus; 33 | 34 | class LTPScaleControl { 35 | 36 | /* Calculation of LTP state scaling */ 37 | static void silk_LTP_scale_ctrl( 38 | SilkChannelEncoder psEnc, /* I/O encoder state */ 39 | SilkEncoderControl psEncCtrl, /* I/O encoder control */ 40 | int condCoding /* I The type of conditional coding to use */ 41 | ) { 42 | int round_loss; 43 | 44 | if (condCoding == SilkConstants.CODE_INDEPENDENTLY) { 45 | /* Only scale if first frame in packet */ 46 | round_loss = psEnc.PacketLoss_perc + psEnc.nFramesPerPacket; 47 | psEnc.indices.LTP_scaleIndex = (byte) Inlines.silk_LIMIT( 48 | Inlines.silk_SMULWB(Inlines.silk_SMULBB(round_loss, psEncCtrl.LTPredCodGain_Q7), ((int) ((0.1f) * ((long) 1 << (9)) + 0.5))/*Inlines.SILK_CONST(0.1f, 9)*/), 0, 2); 49 | } else { 50 | /* Default is minimum scaling */ 51 | psEnc.indices.LTP_scaleIndex = 0; 52 | } 53 | psEncCtrl.LTP_scale_Q14 = SilkTables.silk_LTPScales_table_Q14[psEnc.indices.LTP_scaleIndex]; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/MDCTLookup.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2003-2004, Mark Borgerding 2 | Copyright (c) 2007-2008 CSIRO 3 | Copyright (c) 2007-2011 Xiph.Org Foundation 4 | Modified from KISS-FFT by Jean-Marc Valin 5 | Ported to Java by Logan Stromberg 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 19 | names of specific contributors, may be used to endorse or promote 20 | products derived from this software without specific prior written 21 | permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 27 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | package org.concentus; 36 | 37 | class MDCTLookup { 38 | 39 | int n = 0; 40 | 41 | int maxshift = 0; 42 | 43 | // [porting note] these are pointers to static states defined in tables.cs 44 | FFTState[] kfft = new FFTState[4]; 45 | 46 | short[] trig = null; 47 | 48 | MDCTLookup() { 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/MLP.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2008-2011 Octasic Inc. 2 | Originally written by Jean-Marc Valin 3 | Ported to Java by Logan Stromberg 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 17 | names of specific contributors, may be used to endorse or promote 18 | products derived from this software without specific prior written 19 | permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 25 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | package org.concentus; 34 | 35 | /// 36 | /// state object for multi-layer perceptron 37 | /// 38 | class MLPState { 39 | 40 | int layers; 41 | int[] topo; 42 | float[] weights; 43 | } 44 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/MultiLayerPerceptron.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2008-2011 Octasic Inc. 2 | Originally written by Jean-Marc Valin 3 | Ported to Java by Logan Stromberg 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 17 | names of specific contributors, may be used to endorse or promote 18 | products derived from this software without specific prior written 19 | permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 25 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | package org.concentus; 34 | 35 | /// 36 | /// multi-layer perceptron processor 37 | /// 38 | class MultiLayerPerceptron { 39 | 40 | private static final int MAX_NEURONS = 100; 41 | 42 | static float tansig_approx(float x) { 43 | int i; 44 | float y, dy; 45 | float sign = 1; 46 | /* Tests are reversed to catch NaNs */ 47 | if (!(x < 8)) { 48 | return 1; 49 | } 50 | if (!(x > -8)) { 51 | return -1; 52 | } 53 | if (x < 0) { 54 | x = -x; 55 | sign = -1; 56 | } 57 | i = (int) Math.floor(.5f + 25 * x); 58 | x -= .04f * i; 59 | y = OpusTables.tansig_table[i]; 60 | dy = 1 - y * y; 61 | y = y + x * dy * (1 - y * x); 62 | return sign * y; 63 | } 64 | 65 | static void mlp_process(MLPState m, float[] input, float[] output) { 66 | int j; 67 | float[] hidden = new float[MAX_NEURONS]; 68 | float[] W = m.weights; 69 | int W_ptr = 0; 70 | 71 | /* Copy to tmp_in */ 72 | for (j = 0; j < m.topo[1]; j++) { 73 | int k; 74 | float sum = W[W_ptr]; 75 | W_ptr++; 76 | for (k = 0; k < m.topo[0]; k++) { 77 | sum = sum + input[k] * W[W_ptr]; 78 | W_ptr++; 79 | } 80 | hidden[j] = tansig_approx(sum); 81 | } 82 | 83 | for (j = 0; j < m.topo[2]; j++) { 84 | int k; 85 | float sum = W[W_ptr]; 86 | W_ptr++; 87 | for (k = 0; k < m.topo[1]; k++) { 88 | sum = sum + hidden[k] * W[W_ptr]; 89 | W_ptr++; 90 | } 91 | output[j] = tansig_approx(sum); 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/NLSFCodebook.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006-2011 Skype Limited. All Rights Reserved 2 | Ported to Java by Logan Stromberg 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 16 | names of specific contributors, may be used to endorse or promote 17 | products derived from this software without specific prior written 18 | permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.concentus; 33 | 34 | /// 35 | /// Structure containing NLSF codebook 36 | /// 37 | class NLSFCodebook { 38 | 39 | short nVectors = 0; 40 | 41 | short order = 0; 42 | 43 | /// 44 | /// Quantization step size 45 | /// 46 | short quantStepSize_Q16 = 0; 47 | 48 | /// 49 | /// Inverse quantization step size 50 | /// 51 | short invQuantStepSize_Q6 = 0; 52 | 53 | /// 54 | /// POINTER 55 | /// 56 | short[] CB1_NLSF_Q8 = null; 57 | 58 | /// 59 | /// POINTER 60 | /// 61 | short[] CB1_iCDF = null; 62 | 63 | /// 64 | /// POINTER to Backward predictor coefs [ order ] 65 | /// 66 | short[] pred_Q8 = null; 67 | 68 | /// 69 | /// POINTER to Indices to entropy coding tables [ order ] 70 | /// 71 | short[] ec_sel = null; 72 | 73 | /// 74 | /// POINTER 75 | /// 76 | short[] ec_iCDF = null; 77 | 78 | /// 79 | /// POINTER 80 | /// 81 | short[] ec_Rates_Q5 = null; 82 | 83 | /// 84 | /// POINTER 85 | /// 86 | short[] deltaMin_Q15 = null; 87 | 88 | void Reset() { 89 | nVectors = 0; 90 | order = 0; 91 | quantStepSize_Q16 = 0; 92 | invQuantStepSize_Q6 = 0; 93 | CB1_NLSF_Q8 = null; 94 | CB1_iCDF = null; 95 | pred_Q8 = null; 96 | ec_sel = null; 97 | ec_iCDF = null; 98 | ec_Rates_Q5 = null; 99 | deltaMin_Q15 = null; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/OpusApplication.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2008 CSIRO 2 | Copyright (c) 2007-2011 Xiph.Org Foundation 3 | Originally written by Jean-Marc Valin, Gregory Maxwell, Koen Vos, 4 | Timothy B. Terriberry, and the Opus open-source contributors 5 | Ported to Java by Logan Stromberg 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 19 | names of specific contributors, may be used to endorse or promote 20 | products derived from this software without specific prior written 21 | permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 27 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | package org.concentus; 36 | 37 | public enum OpusApplication { 38 | OPUS_APPLICATION_UNIMPLEMENTED, 39 | /// 40 | /// Best for most VoIP/videoconference applications where listening quality and intelligibility matter most 41 | /// 42 | OPUS_APPLICATION_VOIP, 43 | /// 44 | /// Best for broadcast/high-fidelity application where the decoded audio should be as close as possible to the input 45 | /// 46 | OPUS_APPLICATION_AUDIO, 47 | /// 48 | /// Only use when lowest-achievable latency is what matters most. Voice-optimized modes cannot be used. 49 | /// 50 | OPUS_APPLICATION_RESTRICTED_LOWDELAY 51 | } 52 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/OpusBandwidth.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2008 CSIRO 2 | Copyright (c) 2007-2011 Xiph.Org Foundation 3 | Originally written by Jean-Marc Valin, Gregory Maxwell, Koen Vos, 4 | Timothy B. Terriberry, and the Opus open-source contributors 5 | Ported to Java by Logan Stromberg 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 19 | names of specific contributors, may be used to endorse or promote 20 | products derived from this software without specific prior written 21 | permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 27 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | package org.concentus; 36 | 37 | public enum OpusBandwidth { 38 | OPUS_BANDWIDTH_UNKNOWN, 39 | OPUS_BANDWIDTH_AUTO, 40 | OPUS_BANDWIDTH_NARROWBAND, 41 | OPUS_BANDWIDTH_MEDIUMBAND, 42 | OPUS_BANDWIDTH_WIDEBAND, 43 | OPUS_BANDWIDTH_SUPERWIDEBAND, 44 | OPUS_BANDWIDTH_FULLBAND 45 | } 46 | 47 | // Helpers to port over uses of OpusBandwidth as an integer 48 | class OpusBandwidthHelpers { 49 | 50 | static int GetOrdinal(OpusBandwidth bw) { 51 | switch (bw) { 52 | case OPUS_BANDWIDTH_NARROWBAND: 53 | return 1; 54 | case OPUS_BANDWIDTH_MEDIUMBAND: 55 | return 2; 56 | case OPUS_BANDWIDTH_WIDEBAND: 57 | return 3; 58 | case OPUS_BANDWIDTH_SUPERWIDEBAND: 59 | return 4; 60 | case OPUS_BANDWIDTH_FULLBAND: 61 | return 5; 62 | } 63 | 64 | return -1; 65 | } 66 | 67 | static OpusBandwidth GetBandwidth(int ordinal) { 68 | switch (ordinal) { 69 | case 1: 70 | return OpusBandwidth.OPUS_BANDWIDTH_NARROWBAND; 71 | case 2: 72 | return OpusBandwidth.OPUS_BANDWIDTH_MEDIUMBAND; 73 | case 3: 74 | return OpusBandwidth.OPUS_BANDWIDTH_WIDEBAND; 75 | case 4: 76 | return OpusBandwidth.OPUS_BANDWIDTH_SUPERWIDEBAND; 77 | case 5: 78 | return OpusBandwidth.OPUS_BANDWIDTH_FULLBAND; 79 | } 80 | 81 | return OpusBandwidth.OPUS_BANDWIDTH_AUTO; 82 | } 83 | 84 | static OpusBandwidth MIN(OpusBandwidth a, OpusBandwidth b) { 85 | if (GetOrdinal(a) < GetOrdinal(b)) { 86 | return a; 87 | } 88 | return b; 89 | } 90 | 91 | static OpusBandwidth MAX(OpusBandwidth a, OpusBandwidth b) { 92 | if (GetOrdinal(a) > GetOrdinal(b)) { 93 | return a; 94 | } 95 | return b; 96 | } 97 | 98 | static OpusBandwidth SUBTRACT(OpusBandwidth a, int b) { 99 | return GetBandwidth(GetOrdinal(a) - b); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/OpusConstants.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2008 CSIRO 2 | Copyright (c) 2007-2011 Xiph.Org Foundation 3 | Originally written by Jean-Marc Valin, Gregory Maxwell, Koen Vos, 4 | Timothy B. Terriberry, and the Opus open-source contributors 5 | Ported to Java by Logan Stromberg 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 19 | names of specific contributors, may be used to endorse or promote 20 | products derived from this software without specific prior written 21 | permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 27 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | package org.concentus; 36 | 37 | public class OpusConstants { 38 | 39 | /// 40 | /// Auto/default setting 41 | /// 42 | public static final int OPUS_AUTO = -1000; 43 | 44 | /// 45 | /// Maximum bitrate 46 | /// 47 | public static final int OPUS_BITRATE_MAX = -1; 48 | 49 | // from analysis.c 50 | public static final int NB_FRAMES = 8; 51 | public static final int NB_TBANDS = 18; 52 | public static final int NB_TOT_BANDS = 21; 53 | public static final int NB_TONAL_SKIP_BANDS = 9; 54 | public static final int ANALYSIS_BUF_SIZE = 720; 55 | /* 15 ms at 48 kHz */ 56 | public static final int DETECT_SIZE = 200; 57 | 58 | public static final int MAX_ENCODER_BUFFER = 480; 59 | } 60 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/OpusError.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2008 CSIRO 2 | Copyright (c) 2007-2011 Xiph.Org Foundation 3 | Originally written by Jean-Marc Valin, Gregory Maxwell, Koen Vos, 4 | Timothy B. Terriberry, and the Opus open-source contributors 5 | Ported to Java by Logan Stromberg 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 19 | names of specific contributors, may be used to endorse or promote 20 | products derived from this software without specific prior written 21 | permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 27 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | package org.concentus; 36 | 37 | /// 38 | /// Note that since most API-level errors are detected and thrown as 39 | /// OpusExceptions, direct use of this class is not usually needed 40 | /// 41 | public class OpusError { 42 | 43 | /** 44 | * No error 45 | */ 46 | public static int OPUS_OK = 0; 47 | 48 | /** 49 | * One or more invalid/out of range arguments 50 | */ 51 | public static int OPUS_BAD_ARG = -1; 52 | 53 | /** 54 | * Not enough bytes allocated in the buffer 55 | */ 56 | public static int OPUS_BUFFER_TOO_SMALL = -2; 57 | 58 | /** 59 | * An public error was detected 60 | */ 61 | public static int OPUS_INTERNAL_ERROR = -3; 62 | 63 | /** 64 | * The compressed data passed is corrupted 65 | */ 66 | public static int OPUS_INVALID_PACKET = -4; 67 | 68 | /** 69 | * Invalid/unsupported request number 70 | */ 71 | public static int OPUS_UNIMPLEMENTED = -5; 72 | 73 | /** 74 | * An encoder or decoder structure is invalid or already freed 75 | */ 76 | public static int OPUS_INVALID_STATE = -6; 77 | 78 | /** 79 | * Memory allocation has failed 80 | */ 81 | public static int OPUS_ALLOC_FAIL = -7; 82 | } 83 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/OpusException.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2016 Logan Stromberg 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | - Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | - Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 15 | names of specific contributors, may be used to endorse or promote 16 | products derived from this software without specific prior written 17 | permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 23 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | package org.concentus; 32 | 33 | public class OpusException extends Exception { 34 | 35 | private String _message; 36 | private int _opus_error_code; 37 | 38 | public OpusException() { 39 | this("", 0); 40 | } 41 | 42 | public OpusException(String message) { 43 | this(message, 1); 44 | } 45 | 46 | public OpusException(String message, int opus_error_code) { 47 | _message = message + ": " + CodecHelpers.opus_strerror(opus_error_code); 48 | _opus_error_code = opus_error_code; 49 | } 50 | 51 | @Override 52 | public String getMessage() { 53 | return _message; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/OpusFramesize.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2008 CSIRO 2 | Copyright (c) 2007-2011 Xiph.Org Foundation 3 | Originally written by Jean-Marc Valin, Gregory Maxwell, Koen Vos, 4 | Timothy B. Terriberry, and the Opus open-source contributors 5 | Ported to Java by Logan Stromberg 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 19 | names of specific contributors, may be used to endorse or promote 20 | products derived from this software without specific prior written 21 | permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 27 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | package org.concentus; 36 | 37 | public enum OpusFramesize { 38 | /** 39 | * Error state 40 | */ 41 | OPUS_FRAMESIZE_UNKNOWN, 42 | /// 43 | /// Select frame size from the argument (default) 44 | /// 45 | OPUS_FRAMESIZE_ARG, 46 | /// 47 | /// Use 2.5 ms frames 48 | /// 49 | OPUS_FRAMESIZE_2_5_MS, 50 | /// 51 | /// Use 5 ms frames 52 | /// 53 | OPUS_FRAMESIZE_5_MS, 54 | /// 55 | /// Use 10 ms frames 56 | /// 57 | OPUS_FRAMESIZE_10_MS, 58 | /// 59 | /// Use 20 ms frames 60 | /// 61 | OPUS_FRAMESIZE_20_MS, 62 | /// 63 | /// Use 40 ms frames 64 | /// 65 | OPUS_FRAMESIZE_40_MS, 66 | /// 67 | /// Use 60 ms frames 68 | /// 69 | OPUS_FRAMESIZE_60_MS, 70 | /// 71 | /// Do not use - not fully implemented. Optimize the frame size dynamically. 72 | /// 73 | OPUS_FRAMESIZE_VARIABLE 74 | } 75 | 76 | class OpusFramesizeHelpers { 77 | 78 | static int GetOrdinal(OpusFramesize size) { 79 | switch (size) { 80 | case OPUS_FRAMESIZE_ARG: 81 | return 1; 82 | case OPUS_FRAMESIZE_2_5_MS: 83 | return 2; 84 | case OPUS_FRAMESIZE_5_MS: 85 | return 3; 86 | case OPUS_FRAMESIZE_10_MS: 87 | return 4; 88 | case OPUS_FRAMESIZE_20_MS: 89 | return 5; 90 | case OPUS_FRAMESIZE_40_MS: 91 | return 6; 92 | case OPUS_FRAMESIZE_60_MS: 93 | return 7; 94 | case OPUS_FRAMESIZE_VARIABLE: 95 | return 8; 96 | } 97 | 98 | return -1; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/OpusMode.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2008 CSIRO 2 | Copyright (c) 2007-2011 Xiph.Org Foundation 3 | Originally written by Jean-Marc Valin, Gregory Maxwell, Koen Vos, 4 | Timothy B. Terriberry, and the Opus open-source contributors 5 | Ported to Java by Logan Stromberg 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 19 | names of specific contributors, may be used to endorse or promote 20 | products derived from this software without specific prior written 21 | permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 27 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | package org.concentus; 36 | 37 | public enum OpusMode { 38 | MODE_UNKNOWN, 39 | MODE_AUTO, 40 | MODE_SILK_ONLY, 41 | MODE_HYBRID, 42 | MODE_CELT_ONLY 43 | } 44 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/OpusMultistream.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2008 CSIRO 2 | Copyright (c) 2007-2011 Xiph.Org Foundation 3 | Originally written by Jean-Marc Valin, Gregory Maxwell, Koen Vos, 4 | Timothy B. Terriberry, and the Opus open-source contributors 5 | Ported to Java by Logan Stromberg 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 19 | names of specific contributors, may be used to endorse or promote 20 | products derived from this software without specific prior written 21 | permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 27 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | package org.concentus; 36 | 37 | class OpusMultistream { 38 | 39 | static int validate_layout(ChannelLayout layout) { 40 | int i, max_channel; 41 | 42 | max_channel = layout.nb_streams + layout.nb_coupled_streams; 43 | if (max_channel > 255) { 44 | return 0; 45 | } 46 | for (i = 0; i < layout.nb_channels; i++) { 47 | if (layout.mapping[i] >= max_channel && layout.mapping[i] != 255) { 48 | return 0; 49 | } 50 | } 51 | return 1; 52 | } 53 | 54 | static int get_left_channel(ChannelLayout layout, int stream_id, int prev) { 55 | int i; 56 | i = (prev < 0) ? 0 : prev + 1; 57 | for (; i < layout.nb_channels; i++) { 58 | if (layout.mapping[i] == stream_id * 2) { 59 | return i; 60 | } 61 | } 62 | return -1; 63 | } 64 | 65 | static int get_right_channel(ChannelLayout layout, int stream_id, int prev) { 66 | int i; 67 | i = (prev < 0) ? 0 : prev + 1; 68 | for (; i < layout.nb_channels; i++) { 69 | if (layout.mapping[i] == stream_id * 2 + 1) { 70 | return i; 71 | } 72 | } 73 | return -1; 74 | } 75 | 76 | static int get_mono_channel(ChannelLayout layout, int stream_id, int prev) { 77 | int i; 78 | i = (prev < 0) ? 0 : prev + 1; 79 | for (; i < layout.nb_channels; i++) { 80 | if (layout.mapping[i] == stream_id + layout.nb_coupled_streams) { 81 | return i; 82 | } 83 | } 84 | return -1; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/OpusSignal.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2008 CSIRO 2 | Copyright (c) 2007-2011 Xiph.Org Foundation 3 | Originally written by Jean-Marc Valin, Gregory Maxwell, Koen Vos, 4 | Timothy B. Terriberry, and the Opus open-source contributors 5 | Ported to Java by Logan Stromberg 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 19 | names of specific contributors, may be used to endorse or promote 20 | products derived from this software without specific prior written 21 | permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 27 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | package org.concentus; 36 | 37 | public enum OpusSignal { 38 | OPUS_SIGNAL_UNKNOWN, 39 | OPUS_SIGNAL_AUTO, 40 | /// 41 | /// Signal being encoded is voice 42 | /// 43 | OPUS_SIGNAL_VOICE, 44 | /// 45 | /// Signal being encoded is music 46 | /// 47 | OPUS_SIGNAL_MUSIC 48 | } 49 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/PLCStruct.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006-2011 Skype Limited. All Rights Reserved 2 | Ported to Java by Logan Stromberg 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 16 | names of specific contributors, may be used to endorse or promote 17 | products derived from this software without specific prior written 18 | permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.concentus; 33 | 34 | /// 35 | /// Struct for Packet Loss Concealment 36 | /// 37 | class PLCStruct { 38 | 39 | int pitchL_Q8 = 0; 40 | /* Pitch lag to use for voiced concealment */ 41 | final short[] LTPCoef_Q14 = new short[SilkConstants.LTP_ORDER]; 42 | /* LTP coeficients to use for voiced concealment */ 43 | final short[] prevLPC_Q12 = new short[SilkConstants.MAX_LPC_ORDER]; 44 | int last_frame_lost = 0; 45 | /* Was previous frame lost */ 46 | int rand_seed = 0; 47 | /* Seed for unvoiced signal generation */ 48 | short randScale_Q14 = 0; 49 | /* Scaling of unvoiced random signal */ 50 | int conc_energy = 0; 51 | int conc_energy_shift = 0; 52 | short prevLTP_scale_Q14 = 0; 53 | final int[] prevGain_Q16 = new int[2]; 54 | int fs_kHz = 0; 55 | int nb_subfr = 0; 56 | int subfr_length = 0; 57 | 58 | void Reset() { 59 | pitchL_Q8 = 0; 60 | Arrays.MemSet(LTPCoef_Q14, (short) 0, SilkConstants.LTP_ORDER); 61 | Arrays.MemSet(prevLPC_Q12, (short) 0, SilkConstants.MAX_LPC_ORDER); 62 | last_frame_lost = 0; 63 | rand_seed = 0; 64 | randScale_Q14 = 0; 65 | conc_energy = 0; 66 | conc_energy_shift = 0; 67 | prevLTP_scale_Q14 = 0; 68 | Arrays.MemSet(prevGain_Q16, 0, 2); 69 | fs_kHz = 0; 70 | nb_subfr = 0; 71 | subfr_length = 0; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/PulseCache.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2008 CSIRO 2 | Copyright (c) 2007-2011 Xiph.Org Foundation 3 | Originally written by Jean-Marc Valin, Gregory Maxwell, Koen Vos, 4 | Timothy B. Terriberry, and the Opus open-source contributors 5 | Ported to Java by Logan Stromberg 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 19 | names of specific contributors, may be used to endorse or promote 20 | products derived from this software without specific prior written 21 | permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 27 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | package org.concentus; 36 | 37 | class PulseCache { 38 | 39 | int size = 0; 40 | short[] index = null; 41 | short[] bits = null; 42 | short[] caps = null; 43 | 44 | void Reset() { 45 | size = 0; 46 | index = null; 47 | bits = null; 48 | caps = null; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/RegularizeCorrelations.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006-2011 Skype Limited. All Rights Reserved 2 | Ported to Java by Logan Stromberg 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 16 | names of specific contributors, may be used to endorse or promote 17 | products derived from this software without specific prior written 18 | permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.concentus; 33 | 34 | class RegularizeCorrelations { 35 | 36 | /* Add noise to matrix diagonal */ 37 | static void silk_regularize_correlations( 38 | int[] XX, /* I/O Correlation matrices */ 39 | int XX_ptr, 40 | int[] xx, /* I/O Correlation values */ 41 | int xx_ptr, 42 | int noise, /* I Noise to add */ 43 | int D /* I Dimension of XX */ 44 | ) { 45 | int i; 46 | for (i = 0; i < D; i++) { 47 | Inlines.MatrixSet(XX, XX_ptr, i, i, D, Inlines.silk_ADD32(Inlines.MatrixGet(XX, XX_ptr, i, i, D), noise)); 48 | } 49 | xx[xx_ptr] += noise; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/SideInfoIndices.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006-2011 Skype Limited. All Rights Reserved 2 | Ported to Java by Logan Stromberg 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 16 | names of specific contributors, may be used to endorse or promote 17 | products derived from this software without specific prior written 18 | permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.concentus; 33 | 34 | class SideInfoIndices { 35 | 36 | final byte[] GainsIndices = new byte[SilkConstants.MAX_NB_SUBFR]; 37 | final byte[] LTPIndex = new byte[SilkConstants.MAX_NB_SUBFR]; 38 | final byte[] NLSFIndices = new byte[SilkConstants.MAX_LPC_ORDER + 1]; 39 | short lagIndex = 0; 40 | byte contourIndex = 0; 41 | byte signalType = 0; 42 | byte quantOffsetType = 0; 43 | byte NLSFInterpCoef_Q2 = 0; 44 | byte PERIndex = 0; 45 | byte LTP_scaleIndex = 0; 46 | byte Seed = 0; 47 | 48 | void Reset() { 49 | Arrays.MemSet(GainsIndices, (byte) 0, SilkConstants.MAX_NB_SUBFR); 50 | Arrays.MemSet(LTPIndex, (byte) 0, SilkConstants.MAX_NB_SUBFR); 51 | Arrays.MemSet(NLSFIndices, (byte) 0, SilkConstants.MAX_LPC_ORDER + 1); 52 | lagIndex = 0; 53 | contourIndex = 0; 54 | signalType = 0; 55 | quantOffsetType = 0; 56 | NLSFInterpCoef_Q2 = 0; 57 | PERIndex = 0; 58 | LTP_scaleIndex = 0; 59 | Seed = 0; 60 | } 61 | 62 | /// 63 | /// Overwrites this struct with values from another one. Equivalent to C struct assignment this = other 64 | /// 65 | /// 66 | void Assign(SideInfoIndices other) { 67 | System.arraycopy(other.GainsIndices, 0, this.GainsIndices, 0, SilkConstants.MAX_NB_SUBFR); 68 | System.arraycopy(other.LTPIndex, 0, this.LTPIndex, 0, SilkConstants.MAX_NB_SUBFR); 69 | System.arraycopy(other.NLSFIndices, 0, this.NLSFIndices, 0, SilkConstants.MAX_LPC_ORDER + 1); 70 | this.lagIndex = other.lagIndex; 71 | this.contourIndex = other.contourIndex; 72 | this.signalType = other.signalType; 73 | this.quantOffsetType = other.quantOffsetType; 74 | this.NLSFInterpCoef_Q2 = other.NLSFInterpCoef_Q2; 75 | this.PERIndex = other.PERIndex; 76 | this.LTP_scaleIndex = other.LTP_scaleIndex; 77 | this.Seed = other.Seed; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/Sigmoid.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006-2011 Skype Limited. All Rights Reserved 2 | Ported to Java by Logan Stromberg 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 16 | names of specific contributors, may be used to endorse or promote 17 | products derived from this software without specific prior written 18 | permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.concentus; 33 | 34 | /// 35 | /// Approximate sigmoid function 36 | /// 37 | class Sigmoid { 38 | 39 | private static final int[] sigm_LUT_slope_Q10 = { 40 | 237, 153, 73, 30, 12, 7 41 | }; 42 | 43 | private static final int[] sigm_LUT_pos_Q15 = { 44 | 16384, 23955, 28861, 31213, 32178, 32548 45 | }; 46 | 47 | private static final int[] sigm_LUT_neg_Q15 = { 48 | 16384, 8812, 3906, 1554, 589, 219 49 | }; 50 | 51 | static int silk_sigm_Q15(int in_Q5) { 52 | int ind; 53 | 54 | if (in_Q5 < 0) { 55 | /* Negative input */ 56 | in_Q5 = -in_Q5; 57 | if (in_Q5 >= 6 * 32) { 58 | return 0; 59 | /* Clip */ 60 | } else { 61 | /* Linear interpolation of look up table */ 62 | ind = Inlines.silk_RSHIFT(in_Q5, 5); 63 | return (sigm_LUT_neg_Q15[ind] - Inlines.silk_SMULBB(sigm_LUT_slope_Q10[ind], in_Q5 & 0x1F)); 64 | } 65 | } else /* Positive input */ if (in_Q5 >= 6 * 32) { 66 | return 32767; 67 | /* clip */ 68 | } else { 69 | /* Linear interpolation of look up table */ 70 | ind = Inlines.silk_RSHIFT(in_Q5, 5); 71 | return (sigm_LUT_pos_Q15[ind] + Inlines.silk_SMULBB(sigm_LUT_slope_Q10[ind], in_Q5 & 0x1F)); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/SilkDecoder.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006-2011 Skype Limited. All Rights Reserved 2 | Ported to Java by Logan Stromberg 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 16 | names of specific contributors, may be used to endorse or promote 17 | products derived from this software without specific prior written 18 | permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.concentus; 33 | 34 | /// 35 | /// Decoder super struct 36 | /// 37 | class SilkDecoder { 38 | 39 | final SilkChannelDecoder[] channel_state = new SilkChannelDecoder[SilkConstants.DECODER_NUM_CHANNELS]; 40 | final StereoDecodeState sStereo = new StereoDecodeState(); 41 | int nChannelsAPI = 0; 42 | int nChannelsInternal = 0; 43 | int prev_decode_only_middle = 0; 44 | 45 | SilkDecoder() { 46 | for (int c = 0; c < SilkConstants.DECODER_NUM_CHANNELS; c++) { 47 | channel_state[c] = new SilkChannelDecoder(); 48 | } 49 | } 50 | 51 | void Reset() { 52 | for (int c = 0; c < SilkConstants.DECODER_NUM_CHANNELS; c++) { 53 | channel_state[c].Reset(); 54 | } 55 | sStereo.Reset(); 56 | nChannelsAPI = 0; 57 | nChannelsInternal = 0; 58 | prev_decode_only_middle = 0; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/SilkDecoderControl.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006-2011 Skype Limited. All Rights Reserved 2 | Ported to Java by Logan Stromberg 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 16 | names of specific contributors, may be used to endorse or promote 17 | products derived from this software without specific prior written 18 | permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.concentus; 33 | 34 | /// 35 | /// Decoder control 36 | /// 37 | class SilkDecoderControl { 38 | 39 | /* Prediction and coding parameters */ 40 | final int[] pitchL = new int[SilkConstants.MAX_NB_SUBFR]; 41 | final int[] Gains_Q16 = new int[SilkConstants.MAX_NB_SUBFR]; 42 | 43 | /* Holds interpolated and final coefficients */ 44 | final short[][] PredCoef_Q12 = Arrays.InitTwoDimensionalArrayShort(2, SilkConstants.MAX_LPC_ORDER); 45 | final short[] LTPCoef_Q14 = new short[SilkConstants.LTP_ORDER * SilkConstants.MAX_NB_SUBFR]; 46 | int LTP_scale_Q14 = 0; 47 | 48 | void Reset() { 49 | Arrays.MemSet(pitchL, 0, SilkConstants.MAX_NB_SUBFR); 50 | Arrays.MemSet(Gains_Q16, 0, SilkConstants.MAX_NB_SUBFR); 51 | Arrays.MemSet(PredCoef_Q12[0], (short) 0, SilkConstants.MAX_LPC_ORDER); 52 | Arrays.MemSet(PredCoef_Q12[1], (short) 0, SilkConstants.MAX_LPC_ORDER); 53 | Arrays.MemSet(LTPCoef_Q14, (short) 0, SilkConstants.LTP_ORDER * SilkConstants.MAX_NB_SUBFR); 54 | LTP_scale_Q14 = 0; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/SilkEncoder.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006-2011 Skype Limited. All Rights Reserved 2 | Ported to Java by Logan Stromberg 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 16 | names of specific contributors, may be used to endorse or promote 17 | products derived from this software without specific prior written 18 | permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.concentus; 33 | 34 | /// 35 | /// Encoder Super Struct 36 | /// 37 | class SilkEncoder { 38 | 39 | final SilkChannelEncoder[] state_Fxx = new SilkChannelEncoder[SilkConstants.ENCODER_NUM_CHANNELS]; 40 | final StereoEncodeState sStereo = new StereoEncodeState(); 41 | int nBitsUsedLBRR = 0; 42 | int nBitsExceeded = 0; 43 | int nChannelsAPI = 0; 44 | int nChannelsInternal = 0; 45 | int nPrevChannelsInternal = 0; 46 | int timeSinceSwitchAllowed_ms = 0; 47 | int allowBandwidthSwitch = 0; 48 | int prev_decode_only_middle = 0; 49 | 50 | SilkEncoder() { 51 | for (int c = 0; c < SilkConstants.ENCODER_NUM_CHANNELS; c++) { 52 | state_Fxx[c] = new SilkChannelEncoder(); 53 | } 54 | } 55 | 56 | void Reset() { 57 | for (int c = 0; c < SilkConstants.ENCODER_NUM_CHANNELS; c++) { 58 | state_Fxx[c].Reset(); 59 | } 60 | 61 | sStereo.Reset(); 62 | nBitsUsedLBRR = 0; 63 | nBitsExceeded = 0; 64 | nChannelsAPI = 0; 65 | nChannelsInternal = 0; 66 | nPrevChannelsInternal = 0; 67 | timeSinceSwitchAllowed_ms = 0; 68 | allowBandwidthSwitch = 0; 69 | prev_decode_only_middle = 0; 70 | } 71 | 72 | /// 73 | /// Initialize Silk Encoder state 74 | /// 75 | /// I/O Pointer to Silk FIX encoder state 76 | /// I Run-time architecture 77 | /// 78 | static int silk_init_encoder(SilkChannelEncoder psEnc) { 79 | int ret = 0; 80 | 81 | // Clear the entire encoder state 82 | psEnc.Reset(); 83 | 84 | psEnc.variable_HP_smth1_Q15 = Inlines.silk_LSHIFT(Inlines.silk_lin2log(((int) ((TuningParameters.VARIABLE_HP_MIN_CUTOFF_HZ) * ((long) 1 << (16)) + 0.5))/*Inlines.SILK_CONST(TuningParameters.VARIABLE_HP_MIN_CUTOFF_HZ, 16)*/) - (16 << 7), 8); 85 | psEnc.variable_HP_smth2_Q15 = psEnc.variable_HP_smth1_Q15; 86 | 87 | // Used to deactivate LSF interpolation, pitch prediction 88 | psEnc.first_frame_after_reset = 1; 89 | 90 | // Initialize Silk VAD 91 | ret += VoiceActivityDetection.silk_VAD_Init(psEnc.sVAD); 92 | 93 | return ret; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/SilkError.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006-2011 Skype Limited. All Rights Reserved 2 | Ported to Java by Logan Stromberg 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 16 | names of specific contributors, may be used to endorse or promote 17 | products derived from this software without specific prior written 18 | permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.concentus; 33 | 34 | /// 35 | /// Represents error messages from a silk encoder/decoder 36 | /// 37 | class SilkError { 38 | 39 | static int SILK_NO_ERROR = 0; 40 | 41 | // Encoder error messages 42 | 43 | /* Input length is not a multiple of 10 ms, or length is longer than the packet length */ 44 | static int SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES = -101; 45 | 46 | /* Sampling frequency not 8000, 12000 or 16000 Hertz */ 47 | static int SILK_ENC_FS_NOT_SUPPORTED = -102; 48 | 49 | /* Packet size not 10, 20, 40, or 60 ms */ 50 | static int SILK_ENC_PACKET_SIZE_NOT_SUPPORTED = -103; 51 | 52 | /* Allocated payload buffer too short */ 53 | static int SILK_ENC_PAYLOAD_BUF_TOO_SHORT = -104; 54 | 55 | /* Loss rate not between 0 and 100 percent */ 56 | static int SILK_ENC_INVALID_LOSS_RATE = -105; 57 | 58 | /* Complexity setting not valid, use 0...10 */ 59 | static int SILK_ENC_INVALID_COMPLEXITY_SETTING = -106; 60 | 61 | /* Inband FEC setting not valid, use 0 or 1 */ 62 | static int SILK_ENC_INVALID_INBAND_FEC_SETTING = -107; 63 | 64 | /* DTX setting not valid, use 0 or 1 */ 65 | static int SILK_ENC_INVALID_DTX_SETTING = -108; 66 | 67 | /* CBR setting not valid, use 0 or 1 */ 68 | static int SILK_ENC_INVALID_CBR_SETTING = -109; 69 | 70 | /* Internal encoder error */ 71 | static int SILK_ENC_INTERNAL_ERROR = -110; 72 | 73 | /* Internal encoder error */ 74 | static int SILK_ENC_INVALID_NUMBER_OF_CHANNELS_ERROR = -111; 75 | 76 | // Decoder error messages 77 | 78 | /* Output sampling frequency lower than internal decoded sampling frequency */ 79 | static int SILK_DEC_INVALID_SAMPLING_FREQUENCY = -200; 80 | 81 | /* Payload size exceeded the maximum allowed 1024 bytes */ 82 | static int SILK_DEC_PAYLOAD_TOO_LARGE = -201; 83 | 84 | /* Payload has bit errors */ 85 | static int SILK_DEC_PAYLOAD_ERROR = -202; 86 | 87 | /* Payload has bit errors */ 88 | static int SILK_DEC_INVALID_FRAME_SIZE = -203; 89 | } 90 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/SilkPrefilterState.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006-2011 Skype Limited. All Rights Reserved 2 | Ported to Java by Logan Stromberg 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 16 | names of specific contributors, may be used to endorse or promote 17 | products derived from this software without specific prior written 18 | permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.concentus; 33 | 34 | /// 35 | /// Prefilter state 36 | /// 37 | class SilkPrefilterState { 38 | 39 | final short[] sLTP_shp = new short[SilkConstants.LTP_BUF_LENGTH]; 40 | final int[] sAR_shp = new int[SilkConstants.MAX_SHAPE_LPC_ORDER + 1]; 41 | int sLTP_shp_buf_idx = 0; 42 | int sLF_AR_shp_Q12 = 0; 43 | int sLF_MA_shp_Q12 = 0; 44 | int sHarmHP_Q2 = 0; 45 | int rand_seed = 0; 46 | int lagPrev = 0; 47 | 48 | SilkPrefilterState() { 49 | 50 | } 51 | 52 | void Reset() { 53 | Arrays.MemSet(sLTP_shp, (short) 0, SilkConstants.LTP_BUF_LENGTH); 54 | Arrays.MemSet(sAR_shp, 0, SilkConstants.MAX_SHAPE_LPC_ORDER + 1); 55 | sLTP_shp_buf_idx = 0; 56 | sLF_AR_shp_Q12 = 0; 57 | sLF_MA_shp_Q12 = 0; 58 | sHarmHP_Q2 = 0; 59 | rand_seed = 0; 60 | lagPrev = 0; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/SilkResamplerState.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006-2011 Skype Limited. All Rights Reserved 2 | Ported to Java by Logan Stromberg 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 16 | names of specific contributors, may be used to endorse or promote 17 | products derived from this software without specific prior written 18 | permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.concentus; 33 | 34 | class SilkResamplerState { 35 | 36 | final int[] sIIR = new int[SilkConstants.SILK_RESAMPLER_MAX_IIR_ORDER]; 37 | /* this must be the first element of this struct FIXME why? */ 38 | final int[] sFIR_i32 = new int[SilkConstants.SILK_RESAMPLER_MAX_FIR_ORDER]; // porting note: these two fields were originally a union, so that means only 1 will ever be used at a time. 39 | final short[] sFIR_i16 = new short[SilkConstants.SILK_RESAMPLER_MAX_FIR_ORDER]; 40 | 41 | final short[] delayBuf = new short[48]; 42 | int resampler_function = 0; 43 | int batchSize = 0; 44 | int invRatio_Q16 = 0; 45 | int FIR_Order = 0; 46 | int FIR_Fracs = 0; 47 | int Fs_in_kHz = 0; 48 | int Fs_out_kHz = 0; 49 | int inputDelay = 0; 50 | 51 | /// 52 | /// POINTER 53 | /// 54 | short[] Coefs = null; 55 | 56 | void Reset() { 57 | Arrays.MemSet(sIIR, 0, SilkConstants.SILK_RESAMPLER_MAX_IIR_ORDER); 58 | Arrays.MemSet(sFIR_i32, 0, SilkConstants.SILK_RESAMPLER_MAX_FIR_ORDER); 59 | Arrays.MemSet(sFIR_i16, (short) 0, SilkConstants.SILK_RESAMPLER_MAX_FIR_ORDER); 60 | Arrays.MemSet(delayBuf, (short) 0, 48); 61 | resampler_function = 0; 62 | batchSize = 0; 63 | invRatio_Q16 = 0; 64 | FIR_Order = 0; 65 | FIR_Fracs = 0; 66 | Fs_in_kHz = 0; 67 | Fs_out_kHz = 0; 68 | inputDelay = 0; 69 | Coefs = null; 70 | } 71 | 72 | void Assign(SilkResamplerState other) { 73 | resampler_function = other.resampler_function; 74 | batchSize = other.batchSize; 75 | invRatio_Q16 = other.invRatio_Q16; 76 | FIR_Order = other.FIR_Order; 77 | FIR_Fracs = other.FIR_Fracs; 78 | Fs_in_kHz = other.Fs_in_kHz; 79 | Fs_out_kHz = other.Fs_out_kHz; 80 | inputDelay = other.inputDelay; 81 | Coefs = other.Coefs; 82 | System.arraycopy(other.sIIR, 0, this.sIIR, 0, SilkConstants.SILK_RESAMPLER_MAX_IIR_ORDER); 83 | System.arraycopy(other.sFIR_i32, 0, this.sFIR_i32, 0, SilkConstants.SILK_RESAMPLER_MAX_FIR_ORDER); 84 | System.arraycopy(other.sFIR_i16, 0, this.sFIR_i16, 0, SilkConstants.SILK_RESAMPLER_MAX_FIR_ORDER); 85 | System.arraycopy(other.delayBuf, 0, this.delayBuf, 0, 48); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/SilkShapeState.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006-2011 Skype Limited. All Rights Reserved 2 | Ported to Java by Logan Stromberg 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 16 | names of specific contributors, may be used to endorse or promote 17 | products derived from this software without specific prior written 18 | permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.concentus; 33 | 34 | /// 35 | /// Noise shaping analysis state 36 | /// 37 | class SilkShapeState { 38 | 39 | byte LastGainIndex = 0; 40 | int HarmBoost_smth_Q16 = 0; 41 | int HarmShapeGain_smth_Q16 = 0; 42 | int Tilt_smth_Q16 = 0; 43 | 44 | void Reset() { 45 | LastGainIndex = 0; 46 | HarmBoost_smth_Q16 = 0; 47 | HarmShapeGain_smth_Q16 = 0; 48 | Tilt_smth_Q16 = 0; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/SilkVADState.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006-2011 Skype Limited. All Rights Reserved 2 | Ported to Java by Logan Stromberg 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 16 | names of specific contributors, may be used to endorse or promote 17 | products derived from this software without specific prior written 18 | permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.concentus; 33 | 34 | /// 35 | /// VAD state 36 | /// 37 | class SilkVADState { 38 | 39 | /// 40 | /// Analysis filterbank state: 0-8 kHz 41 | /// 42 | final int[] AnaState = new int[2]; 43 | 44 | /// 45 | /// Analysis filterbank state: 0-4 kHz 46 | /// 47 | final int[] AnaState1 = new int[2]; 48 | 49 | /// 50 | /// Analysis filterbank state: 0-2 kHz 51 | /// 52 | final int[] AnaState2 = new int[2]; 53 | 54 | /// 55 | /// Subframe energies 56 | /// 57 | final int[] XnrgSubfr = new int[SilkConstants.VAD_N_BANDS]; 58 | 59 | /// 60 | /// Smoothed energy level in each band 61 | /// 62 | final int[] NrgRatioSmth_Q8 = new int[SilkConstants.VAD_N_BANDS]; 63 | 64 | /// 65 | /// State of differentiator in the lowest band 66 | /// 67 | short HPstate = 0; 68 | 69 | /// 70 | /// Noise energy level in each band 71 | /// 72 | final int[] NL = new int[SilkConstants.VAD_N_BANDS]; 73 | 74 | /// 75 | /// Inverse noise energy level in each band 76 | /// 77 | final int[] inv_NL = new int[SilkConstants.VAD_N_BANDS]; 78 | 79 | /// 80 | /// Noise level estimator bias/offset 81 | /// 82 | final int[] NoiseLevelBias = new int[SilkConstants.VAD_N_BANDS]; 83 | 84 | /// 85 | /// Frame counter used in the initial phase 86 | /// 87 | int counter = 0; 88 | 89 | void Reset() { 90 | Arrays.MemSet(AnaState, 0, 2); 91 | Arrays.MemSet(AnaState1, 0, 2); 92 | Arrays.MemSet(AnaState2, 0, 2); 93 | Arrays.MemSet(XnrgSubfr, 0, SilkConstants.VAD_N_BANDS); 94 | Arrays.MemSet(NrgRatioSmth_Q8, 0, SilkConstants.VAD_N_BANDS); 95 | HPstate = 0; 96 | Arrays.MemSet(NL, 0, SilkConstants.VAD_N_BANDS); 97 | Arrays.MemSet(inv_NL, 0, SilkConstants.VAD_N_BANDS); 98 | Arrays.MemSet(NoiseLevelBias, 0, SilkConstants.VAD_N_BANDS); 99 | counter = 0; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/Spread.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2008 CSIRO 2 | Copyright (c) 2007-2011 Xiph.Org Foundation 3 | Originally written by Jean-Marc Valin, Gregory Maxwell, Koen Vos, 4 | Timothy B. Terriberry, and the Opus open-source contributors 5 | Ported to Java by Logan Stromberg 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 19 | names of specific contributors, may be used to endorse or promote 20 | products derived from this software without specific prior written 21 | permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 27 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | package org.concentus; 36 | 37 | class Spread { 38 | 39 | public static final int SPREAD_NONE = 0; 40 | public static final int SPREAD_LIGHT = 1; 41 | public static final int SPREAD_NORMAL = 2; 42 | public static final int SPREAD_AGGRESSIVE = 3; 43 | } 44 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/StereoDecodeState.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006-2011 Skype Limited. All Rights Reserved 2 | Ported to Java by Logan Stromberg 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 16 | names of specific contributors, may be used to endorse or promote 17 | products derived from this software without specific prior written 18 | permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.concentus; 33 | 34 | class StereoDecodeState { 35 | 36 | final short[] pred_prev_Q13 = new short[2]; 37 | final short[] sMid = new short[2]; 38 | final short[] sSide = new short[2]; 39 | 40 | void Reset() { 41 | Arrays.MemSet(pred_prev_Q13, (short) 0, 2); 42 | Arrays.MemSet(sMid, (short) 0, 2); 43 | Arrays.MemSet(sSide, (short) 0, 2); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/StereoEncodeState.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006-2011 Skype Limited. All Rights Reserved 2 | Ported to Java by Logan Stromberg 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 16 | names of specific contributors, may be used to endorse or promote 17 | products derived from this software without specific prior written 18 | permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.concentus; 33 | 34 | class StereoEncodeState { 35 | 36 | final short[] pred_prev_Q13 = new short[2]; 37 | final short[] sMid = new short[2]; 38 | final short[] sSide = new short[2]; 39 | final int[] mid_side_amp_Q0 = new int[4]; 40 | short smth_width_Q14 = 0; 41 | short width_prev_Q14 = 0; 42 | short silent_side_len = 0; 43 | final byte[][][] predIx = Arrays.InitThreeDimensionalArrayByte(SilkConstants.MAX_FRAMES_PER_PACKET, 2, 3); 44 | final byte[] mid_only_flags = new byte[SilkConstants.MAX_FRAMES_PER_PACKET]; 45 | 46 | void Reset() { 47 | Arrays.MemSet(pred_prev_Q13, (short) 0, 2); 48 | Arrays.MemSet(sMid, (short) 0, 2); 49 | Arrays.MemSet(sSide, (short) 0, 2); 50 | Arrays.MemSet(mid_side_amp_Q0, 0, 4); 51 | smth_width_Q14 = 0; 52 | width_prev_Q14 = 0; 53 | silent_side_len = 0; 54 | for (int x = 0; x < SilkConstants.MAX_FRAMES_PER_PACKET; x++) { 55 | for (int y = 0; y < 2; y++) { 56 | Arrays.MemSet(predIx[x][y], (byte) 0, 3); 57 | } 58 | } 59 | 60 | Arrays.MemSet(mid_only_flags, (byte) 0, SilkConstants.MAX_FRAMES_PER_PACKET); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/StereoWidthState.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2008 CSIRO 2 | Copyright (c) 2007-2011 Xiph.Org Foundation 3 | Originally written by Jean-Marc Valin, Gregory Maxwell, Koen Vos, 4 | Timothy B. Terriberry, and the Opus open-source contributors 5 | Ported to Java by Logan Stromberg 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 19 | names of specific contributors, may be used to endorse or promote 20 | products derived from this software without specific prior written 21 | permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 27 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | package org.concentus; 36 | 37 | class StereoWidthState { 38 | 39 | int XX; 40 | int XY; 41 | int YY; 42 | int smoothed_width; 43 | int max_follower; 44 | 45 | void Reset() { 46 | XX = 0; 47 | XY = 0; 48 | YY = 0; 49 | smoothed_width = 0; 50 | max_follower = 0; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/TOCStruct.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006-2011 Skype Limited. All Rights Reserved 2 | Ported to Java by Logan Stromberg 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 16 | names of specific contributors, may be used to endorse or promote 17 | products derived from this software without specific prior written 18 | permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.concentus; 33 | 34 | /// 35 | /// Struct for TOC (Table of Contents) 36 | /// 37 | class TOCStruct { 38 | 39 | /// 40 | /// Voice activity for packet 41 | /// 42 | int VADFlag = 0; 43 | 44 | /// 45 | /// Voice activity for each frame in packet 46 | /// 47 | final int[] VADFlags = new int[SilkConstants.SILK_MAX_FRAMES_PER_PACKET]; 48 | 49 | /// 50 | /// Flag indicating if packet contains in-band FEC 51 | /// 52 | int inbandFECFlag = 0; 53 | 54 | void Reset() { 55 | VADFlag = 0; 56 | Arrays.MemSet(VADFlags, 0, SilkConstants.SILK_MAX_FRAMES_PER_PACKET); 57 | inbandFECFlag = 0; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /r1-server/src/main/java/org/concentus/VorbisLayout.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2008 CSIRO 2 | Copyright (c) 2007-2011 Xiph.Org Foundation 3 | Originally written by Jean-Marc Valin, Gregory Maxwell, Koen Vos, 4 | Timothy B. Terriberry, and the Opus open-source contributors 5 | Ported to Java by Logan Stromberg 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 19 | names of specific contributors, may be used to endorse or promote 20 | products derived from this software without specific prior written 21 | permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 27 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | package org.concentus; 36 | 37 | class VorbisLayout { 38 | 39 | VorbisLayout(int streams, int coupled_streams, short[] map) { 40 | nb_streams = streams; 41 | nb_coupled_streams = coupled_streams; 42 | mapping = map; 43 | } 44 | 45 | int nb_streams; 46 | int nb_coupled_streams; 47 | short[] mapping; 48 | 49 | /* Index is nb_channel-1*/ 50 | static final VorbisLayout[] vorbis_mappings = { 51 | new VorbisLayout(1, 0, new short[]{0}), /* 1: mono */ 52 | new VorbisLayout(1, 1, new short[]{0, 1}), /* 2: stereo */ 53 | new VorbisLayout(2, 1, new short[]{0, 2, 1}), /* 3: 1-d surround */ 54 | new VorbisLayout(2, 2, new short[]{0, 1, 2, 3}), /* 4: quadraphonic surround */ 55 | new VorbisLayout(3, 2, new short[]{0, 4, 1, 2, 3}), /* 5: 5-channel surround */ 56 | new VorbisLayout(4, 2, new short[]{0, 4, 1, 2, 3, 5}), /* 6: 5.1 surround */ 57 | new VorbisLayout(4, 3, new short[]{0, 4, 1, 2, 3, 5, 6}), /* 7: 6.1 surround */ 58 | new VorbisLayout(5, 3, new short[]{0, 6, 1, 2, 3, 4, 5, 7}), /* 8: 7.1 surround */}; 59 | } 60 | -------------------------------------------------------------------------------- /r1-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.address=0.0.0.0 2 | spring.application.name=r1-iot 3 | server.port=80 4 | spring.mvc.pathmatch.matching-strategy=ant_path_matcher 5 | -------------------------------------------------------------------------------- /r1-server/src/main/resources/scripts/manage_cloudflared.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 参数检查 4 | if [ "$#" -ne 1 ]; then 5 | echo "Usage: $0 " 6 | exit 1 7 | fi 8 | 9 | SERVICE_ID=$1 10 | 11 | cloudflared service uninstall 12 | 13 | # 2. 启动新进程(后台运行,记录PID) 14 | echo "Starting $SERVICE_NAME with serviceId: $SERVICE_ID..." 15 | cloudflared service install "$SERVICE_ID" 16 | -------------------------------------------------------------------------------- /r1-server/src/test/java/huan/diy/r1iot/AITest.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot; 2 | 3 | import dev.langchain4j.agent.tool.P; 4 | import dev.langchain4j.agent.tool.Tool; 5 | import dev.langchain4j.memory.chat.MessageWindowChatMemory; 6 | import dev.langchain4j.model.chat.ChatLanguageModel; 7 | import dev.langchain4j.model.openai.OpenAiChatModel; 8 | import dev.langchain4j.service.AiServices; 9 | import org.junit.jupiter.api.Test; 10 | 11 | import java.util.function.Function; 12 | 13 | public class AITest { 14 | 15 | 16 | static class BoxDecision { 17 | 18 | @Tool(""" 19 | 用于回答用户的一般提问 20 | """) 21 | String questionAnswer(@P("用户输入") String userInput) { 22 | System.out.println("Called questionAnswer with userInput=" + userInput); 23 | return userInput; 24 | } 25 | 26 | @Tool(""" 27 | 用于处理播放音乐请求 28 | """) 29 | void playMusic(@P(value = "歌曲作者,可以为空字符串", required = false) String author, 30 | @P(value = "歌曲名称,可以为空字符串", required = false) String songName, 31 | @P(value = "歌曲搜索关键词,可以为空字符串", required = false) String keyword) { 32 | System.out.println("Called playMusic with author=" + author + ", songName=" + songName + ", keyword=" + keyword); 33 | } 34 | 35 | @Tool(""" 36 | 音箱一般设置:氛围灯,音量,停止,休眠等等 37 | """) 38 | void voiceBoxSetting(@P("用户输入") String userInput) { 39 | System.out.println("Called voiceBoxSetting with userInput=" + userInput); 40 | } 41 | 42 | @Tool(""" 43 | 智能家居控制,比如打开灯、热得快,空调,调节温度,查询湿度,等等 44 | """) 45 | void homeassistant(String actionCommand) { 46 | System.out.println("Called homeassistant with actionCommand=" + actionCommand ); 47 | } 48 | 49 | @Tool(""" 50 | 用于播放新闻,比如体育、财经、科技、娱乐等等 51 | """) 52 | void playNews(@P("用户输入") String userInput) { 53 | System.out.println("Called playNews with userInput=" + userInput); 54 | } 55 | 56 | @Tool(""" 57 | 用于播放故事、广播等 58 | """) 59 | void playAudio(@P("关键词") String keyword) { 60 | System.out.println("Called playAudio with userInput=" + keyword); 61 | } 62 | 63 | 64 | } 65 | 66 | interface Assistant { 67 | 68 | String chat(String userMessage); 69 | } 70 | 71 | @Test 72 | public void mainTest() { 73 | 74 | Function systemMessageProvider = (context) -> { 75 | return """ 76 | 你是一个智能音箱助手,负责处理用户的语音指令。 77 | 78 | 注意: 79 | 你每次只需要使用一个功能,不要同时使用多个功能。 80 | """; 81 | }; 82 | 83 | ChatLanguageModel model = OpenAiChatModel.builder() 84 | .baseUrl("https://api.x.ai/v1") 85 | .apiKey("xai-MAPslh") 86 | .modelName("grok-2-latest") 87 | .strictTools(false) 88 | .build(); 89 | 90 | Assistant assistant = AiServices.builder(Assistant.class) 91 | .chatLanguageModel(model) 92 | 93 | .tools(new BoxDecision()) 94 | .chatMemory(MessageWindowChatMemory.withMaxMessages(10)) 95 | .systemMessageProvider(systemMessageProvider) // 使用 Provider 方式设置 SystemMessage 96 | 97 | .build(); 98 | 99 | String question = "小白兔白又白是个啥?"; 100 | 101 | String answer = assistant.chat(question); 102 | answer = assistant.chat("播放它"); 103 | 104 | System.out.println(answer); 105 | // The square root of the sum of the number of letters in the words "hello" and "world" is approximately 3.162. 106 | } 107 | 108 | 109 | } 110 | -------------------------------------------------------------------------------- /r1-server/src/test/java/huan/diy/r1iot/R1IotApplicationTests.java: -------------------------------------------------------------------------------- 1 | package huan.diy.r1iot; 2 | 3 | import com.fasterxml.jackson.core.JsonProcessingException; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import huan.diy.r1iot.util.R1IotUtils; 6 | import org.junit.jupiter.api.Test; 7 | 8 | class R1IotApplicationTests { 9 | 10 | @Test 11 | void contextLoads() throws JsonProcessingException { 12 | String str = "\":{\"mood\":\"中性\",\"style\":\"HIGH_QUALITY\",\"text\":\"上海很美丽的你带我去看看吧\"},\"returnCode\":0,\"retTag\":\"nlu\",\"service\":\"cn.yunzhisheng.chat\",\"nluProcessTime\":\"526\",\"text\":\"上海交\",\"responseId\":\"c0fa3fc02a7d49c5bd14c26c83535fa9\"}"; 13 | ObjectMapper objectMapper = new ObjectMapper(); 14 | System.out.println(objectMapper.readTree(str)); 15 | } 16 | 17 | @Test 18 | public void chinese(){ 19 | System.out.println("好的!很高兴跟你聊天。你想聊些什么呢?可以告诉我你的兴趣爱好,或者有什么问题想问?\uD83D\uDE0A" 20 | .replaceAll(R1IotUtils.CHINESE, "")); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /r1-web/.env.development: -------------------------------------------------------------------------------- 1 | REACT_APP_API_URL=http://localhost:8080/ -------------------------------------------------------------------------------- /r1-web/.env.production: -------------------------------------------------------------------------------- 1 | REACT_APP_API_URL=/ -------------------------------------------------------------------------------- /r1-web/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 35 | 36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 39 | 40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | -------------------------------------------------------------------------------- /r1-web/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "r1-web", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/dom": "^10.4.0", 7 | "@testing-library/jest-dom": "^6.6.3", 8 | "@testing-library/react": "^16.2.0", 9 | "@testing-library/user-event": "^13.5.0", 10 | "@types/jest": "^27.5.2", 11 | "@types/node": "^16.18.126", 12 | "@types/react": "^18", 13 | "@types/react-dom": "^18", 14 | "antd": "^5.24.4", 15 | "axios": "^1.8.3", 16 | "react": "^18", 17 | "react-dom": "^18", 18 | "react-router-dom": "^7.3.0", 19 | "react-scripts": "5.0.1", 20 | "typescript": "^4.9.5", 21 | "web-vitals": "^2.1.4" 22 | }, 23 | "scripts": { 24 | "start": "react-scripts start", 25 | "build": "react-scripts build", 26 | "test": "react-scripts test", 27 | "eject": "react-scripts eject" 28 | }, 29 | "eslintConfig": { 30 | "extends": [ 31 | "react-app", 32 | "react-app/jest" 33 | ] 34 | }, 35 | "browserslist": { 36 | "production": [ 37 | ">0.2%", 38 | "not dead", 39 | "not op_mini all" 40 | ], 41 | "development": [ 42 | "last 1 chrome version", 43 | "last 1 firefox version", 44 | "last 1 safari version" 45 | ] 46 | }, 47 | "devDependencies": { 48 | "@types/file-saver": "^2.0.7" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /r1-web/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | huan.diy 14 | r1-web 15 | 0.0.1-SNAPSHOT 16 | jar 17 | r1-web 18 | 19 | 20 | 21 | 22 | com.github.eirslett 23 | frontend-maven-plugin 24 | 1.12.1 25 | 26 | 27 | install node and npm 28 | 29 | install-node-and-npm 30 | 31 | 32 | v20.18.0 33 | 10.8.2 34 | 35 | 36 | 37 | npm install 38 | 39 | npm 40 | 41 | 42 | install 43 | 44 | 45 | 46 | npm build 47 | 48 | npm 49 | 50 | 51 | run build 52 | 53 | 54 | 55 | 56 | 57 | maven-resources-plugin 58 | 3.2.0 59 | 60 | 61 | copy-react-build 62 | prepare-package 63 | 64 | copy-resources 65 | 66 | 67 | ${project.build.outputDirectory}/static 68 | 69 | 70 | ${project.basedir}/build 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /r1-web/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ring1012/r1-iot-java/297da76776af2cde446febc0363498f855fdd686/r1-web/public/favicon.ico -------------------------------------------------------------------------------- /r1-web/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /r1-web/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ring1012/r1-iot-java/297da76776af2cde446febc0363498f855fdd686/r1-web/public/logo192.png -------------------------------------------------------------------------------- /r1-web/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ring1012/r1-iot-java/297da76776af2cde446febc0363498f855fdd686/r1-web/public/logo512.png -------------------------------------------------------------------------------- /r1-web/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /r1-web/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /r1-web/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /r1-web/src/components/api.ts: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | 3 | // 创建一个 axios 实例 4 | const axiosInstance = axios.create({ 5 | }); 6 | 7 | // 添加请求拦截器 8 | axiosInstance.interceptors.request.use( 9 | (config) => { 10 | // 从 localStorage 中获取 token 11 | const token = localStorage.getItem('token'); // 假设你存储在 localStorage 中的 key 为 'token' 12 | 13 | // 如果 token 存在,将其添加到 Authorization 请求头中 14 | if (token) { 15 | config.headers['Authorization'] = `${token}`; 16 | } 17 | 18 | // 返回请求配置 19 | return config; 20 | }, 21 | (error) => { 22 | // 请求失败时的错误处理 23 | return Promise.reject(error); 24 | } 25 | ); 26 | 27 | // 导出 axios 实例 28 | export default axiosInstance; 29 | -------------------------------------------------------------------------------- /r1-web/src/components/pop_pass.tsx: -------------------------------------------------------------------------------- 1 | import React, {useState, useEffect} from 'react'; 2 | import {Button, Input, Modal} from 'antd'; 3 | import type {InputRef} from 'antd'; 4 | import axiosInstance from "./api"; 5 | 6 | const PasswordModal = ({onClose}: { onClose: () => void }) => { 7 | const [password, setPassword] = useState(''); 8 | const inputRef = React.useRef(null); 9 | 10 | // 聚焦输入框 11 | useEffect(() => { 12 | inputRef.current?.focus(); 13 | }, []); 14 | const apiURL = process.env.REACT_APP_API_URL; 15 | 16 | // 处理提交 17 | const handleSubmit = async () => { 18 | if (!password) { 19 | Modal.warning({ 20 | title: '提示', 21 | content: '请输入密码', 22 | }); 23 | return; 24 | } 25 | 26 | 27 | try { 28 | const response = await axiosInstance.post(`${apiURL}auth`, {password}); 29 | if (response.status === 200) { 30 | window.localStorage.setItem("token", response.data); 31 | Modal.success({ 32 | title: '成功', 33 | content: '密码验证成功', 34 | }); 35 | // 刷新当前页面 36 | window.location.reload(); 37 | } 38 | } catch (err) { 39 | console.error('验证失败:', err); 40 | 41 | Modal.error({ 42 | title: '错误', 43 | content: '密码验证失败', 44 | }); 45 | } 46 | 47 | onClose(); 48 | 49 | }; 50 | 51 | // 处理键盘事件 52 | const handleKeyDown = (e: React.KeyboardEvent) => { 53 | if (e.key === 'Enter') { 54 | handleSubmit(); 55 | } 56 | }; 57 | 58 | return ( 59 |
71 |

请输入密码

72 | setPassword(e.target.value)} 76 | placeholder="系统启动时env参数password" 77 | style={{width: '100%', marginBottom: '16px'}} 78 | onKeyDown={handleKeyDown} 79 | /> 80 |
81 | 87 | 94 |
95 |
96 | ); 97 | }; 98 | 99 | export default PasswordModal; -------------------------------------------------------------------------------- /r1-web/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /r1-web/src/index.tsx: -------------------------------------------------------------------------------- 1 | // @ts-ignore 2 | import React, {useState} from 'react'; 3 | import {ConfigProvider, Menu, Layout, Button} from 'antd'; 4 | // 由于 antd 组件的默认文案是英文,所以需要修改为中文 5 | // @ts-ignore 6 | import dayjs from 'dayjs'; 7 | import {createRoot} from 'react-dom/client'; 8 | import {BrowserRouter as Router, Routes, Route, Link, useLocation} from 'react-router-dom'; 9 | 10 | import 'dayjs/locale/zh-cn'; 11 | 12 | import zhCN from 'antd/locale/zh_CN'; 13 | 14 | import './index.css'; 15 | import Box from "./pages/home"; 16 | import Server from "./pages/server"; 17 | import {CloudOutlined, SoundOutlined, MenuUnfoldOutlined, MenuFoldOutlined} from "@ant-design/icons"; 18 | 19 | const {Sider} = Layout; 20 | 21 | dayjs.locale('zh-cn'); 22 | 23 | // 菜单组件 24 | const VerticalMenu = () => { 25 | const location = useLocation(); 26 | 27 | return ( 28 | 33 | } 36 | > 37 | 音箱配置 38 | 39 | 40 | } 43 | > 44 | 服务器配置 45 | 46 | 47 | ); 48 | }; 49 | 50 | const App = () => { 51 | 52 | const [collapsed, setCollapsed] = useState(true); 53 | 54 | // @ts-ignore 55 | return ( 56 | 57 | 58 | 59 | setCollapsed(value)} 65 | trigger={null} // 隐藏默认的折叠触发器 66 | > 67 |
68 |
75 | 76 |
77 | 78 | 79 | }/> 80 | }/> 81 | 82 | 83 |
84 |
85 |
86 | ); 87 | }; 88 | 89 | // @ts-ignore 90 | createRoot(document.getElementById('root')).render(); -------------------------------------------------------------------------------- /r1-web/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /r1-web/src/model/R1AdminData.ts: -------------------------------------------------------------------------------- 1 | export interface AIConfig { 2 | choice: string; 3 | key: string; 4 | systemPrompt: string; 5 | chatHistoryNum: number; 6 | } 7 | 8 | export interface HASSConfig { 9 | endpoint: string; 10 | token: string; 11 | } 12 | 13 | export interface WeatherConfig { 14 | choice: string; 15 | endpoint: string; 16 | token: string; 17 | locationId: string; 18 | } 19 | 20 | export interface MusicConfig { 21 | choice: string; 22 | endpoint?: string; 23 | } 24 | 25 | 26 | export interface Device { 27 | id: string; 28 | name: string; 29 | aiConfig: AIConfig; 30 | hassConfig: HASSConfig; 31 | newsConfig: MusicConfig; 32 | musicConfig: MusicConfig; 33 | audioConfig: MusicConfig; 34 | weatherConfig: WeatherConfig; 35 | } 36 | 37 | export interface ServiceAliasName { 38 | serviceName: string; 39 | aliasName: string; 40 | } 41 | 42 | export interface R1Resources { 43 | aiList: ServiceAliasName[]; 44 | musicList: ServiceAliasName[]; 45 | newsList: ServiceAliasName[]; 46 | audioList: ServiceAliasName[]; 47 | weatherList: ServiceAliasName[]; 48 | cityLocations: CityLocation[]; 49 | } 50 | 51 | export interface R1AdminData { 52 | r1Resources: R1Resources; 53 | devices: Device[]; 54 | currentDeviceId: string; 55 | r1GlobalConfig: R1GlobalConfig; 56 | } 57 | 58 | export interface R1GlobalConfig { 59 | hostIp: string; 60 | ytdlpEndpoint: string; 61 | cfServiceId: string; 62 | } 63 | 64 | export interface CityLocation { 65 | cityName: string; 66 | locationId: string; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /r1-web/src/pages/home/home.css: -------------------------------------------------------------------------------- 1 | /* DeviceManagement.css */ 2 | .container { 3 | padding: 24px; 4 | background-color: #f0f2f5; 5 | display: flex; 6 | justify-content: center; 7 | } 8 | 9 | .card-container { 10 | width: 800px; 11 | max-width: 100%; 12 | background-color: #fff; 13 | border-radius: 8px; 14 | box-shadow: 0px 2px 10px rgba(0, 0, 0, 0.1); 15 | } 16 | 17 | .tabs { 18 | background: #ececec; 19 | color: #4d4d4d; 20 | } 21 | 22 | .tab-button { 23 | background-color: #6c9eeb; 24 | } 25 | 26 | .form-input { 27 | border-radius: 4px; 28 | border-color: #b3d4fc; 29 | } 30 | 31 | .card-title { 32 | background-color: #f7f7f7; 33 | border-radius: 8px; 34 | } 35 | 36 | .button-save { 37 | background-color: #7ac7b8; 38 | border-radius: 4px; 39 | margin-top: 12px; 40 | } 41 | -------------------------------------------------------------------------------- /r1-web/src/pages/server/server.css: -------------------------------------------------------------------------------- 1 | .container { 2 | padding: 24px; 3 | background-color: #f0f2f5; 4 | display: flex; 5 | justify-content: center; 6 | } 7 | 8 | .card-container { 9 | width: 800px; 10 | max-width: 100%; 11 | background-color: #fff; 12 | border-radius: 8px; 13 | box-shadow: 0px 2px 10px rgba(0, 0, 0, 0.1); 14 | } 15 | 16 | .tabs { 17 | background: #ececec; 18 | color: #4d4d4d; 19 | } 20 | 21 | .tab-button { 22 | background-color: #6c9eeb; 23 | } 24 | 25 | .form-input { 26 | border-radius: 4px; 27 | border-color: #b3d4fc; 28 | } 29 | 30 | .card-title { 31 | background-color: #f7f7f7; 32 | border-radius: 8px; 33 | } 34 | 35 | .button-save { 36 | background-color: #7ac7b8; 37 | border-radius: 4px; 38 | margin-top: 12px; 39 | } 40 | -------------------------------------------------------------------------------- /r1-web/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /r1-web/src/reportWebVitals.ts: -------------------------------------------------------------------------------- 1 | import { ReportHandler } from 'web-vitals'; 2 | 3 | const reportWebVitals = (onPerfEntry?: ReportHandler) => { 4 | if (onPerfEntry && onPerfEntry instanceof Function) { 5 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 6 | getCLS(onPerfEntry); 7 | getFID(onPerfEntry); 8 | getFCP(onPerfEntry); 9 | getLCP(onPerfEntry); 10 | getTTFB(onPerfEntry); 11 | }); 12 | } 13 | }; 14 | 15 | export default reportWebVitals; 16 | -------------------------------------------------------------------------------- /r1-web/src/setupTests.ts: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /r1-web/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "noFallthroughCasesInSwitch": true, 16 | "module": "esnext", 17 | "moduleResolution": "node", 18 | "resolveJsonModule": true, 19 | "isolatedModules": true, 20 | "noEmit": true, 21 | "jsx": "react-jsx" 22 | }, 23 | "include": [ 24 | "src" 25 | ] 26 | } 27 | --------------------------------------------------------------------------------